Esempio n. 1
0
def object_data_pretty_printer(map_id):
    map = extract_maps.map_headers[map_id]
    output = ""

    label_name = make_object_label_name(map["name"])
    object_data_pointer = map["object_data_pointer"]
    object = map["object_data"]
    size = extract_maps.compute_object_data_size(object)

    output += label_name + ": ; " + object_data_pointer + " (size=" + str(
        size) + ")\n"
    output += spacing + "db $" + hex(
        object["maps_border_tile"])[2:] + " ; border tile\n"
    output += "\n"
    output += spacing + "db $" + hex(int(
        object["number_of_warps"]))[2:] + " ; warps\n"

    #warps
    for warp_id in object["warps"]:
        warp = object["warps"][warp_id]
        y = warp["y"]
        x = warp["x"]
        warp_to_point = warp["warp_to_point"]
        warp_to_map_id = warp["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"
def object_data_pretty_printer(map_id):
    map = extract_maps.map_headers[map_id]
    output = ""

    label_name = make_object_label_name(map["name"])
    object_data_pointer = map["object_data_pointer"]
    object = map["object_data"]
    size = extract_maps.compute_object_data_size(object)
    
    output += label_name + ": ; " + object_data_pointer + " (size=" + str(size) + ")\n"
    output += spacing + "db $" + hex(object["maps_border_tile"])[2:] + " ; border tile\n"
    output += "\n"
    output += spacing + "db $" + hex(int(object["number_of_warps"]))[2:] + " ; warps\n"

    #warps
    for warp_id in object["warps"]:
        warp = object["warps"][warp_id]
        y = warp["y"]
        x = warp["x"]
        warp_to_point = warp["warp_to_point"]
        warp_to_map_id = warp["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"
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_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)