Exemplo n.º 1
0
    def compile(self) -> (MessageType, str):
        content_lines = self.content.split('\n')
        self.bin.append(get_hex(load_zero_instruction))
        line = 1
        for content_line in content_lines:

            content_line_raw_instruction = content_line.split(' ')
            log.info(content_line_raw_instruction)

            if content_line_raw_instruction[0] == '':
                continue
            elif len(content_line_raw_instruction) < 4:
                log.error("Error: instruction over/under 4 parts line:", line)

            content_line_instruction_opcode = get_opcode(
                content_line_raw_instruction[0])
            content_line_instruction_arg1 = content_line_raw_instruction[1]
            content_line_instruction_arg2 = content_line_raw_instruction[2]
            content_line_instruction_arg3 = content_line_raw_instruction[3]
            temp_instruction = Instruction(content_line_instruction_opcode,
                                           content_line_instruction_arg1,
                                           content_line_instruction_arg2,
                                           content_line_instruction_arg3,
                                           False)

            message_type, message = check(temp_instruction)
            if message_type == MessageType.InstructionError:
                log.error("Error:", message, "Line", line)
                exit(4)
            elif message_type == MessageType.InstructionWarning:
                log.warning("Warning:", message, "Line:", line)
            else:
                log.info("Done Line:", line)
                self.bin.append(get_hex(temp_instruction))
            line = line + 1
Exemplo n.º 2
0
def allocate_check(nodes, actor):
    # Unpack the actor info
    actor_id = actor[0]
    dal_timer = actor[1]

    # Get the relevant row in the actor lookup table:
    lookup_row = lookup[lookup[:, 0] == actor_id]
    if np.size(lookup_row) == 0:
        sys.exit(
            "Actor id " + t.get_hex(actor_id, 4) +
            " is not a valid actor. Check 'actorset.txt' and 'actorset.txt' for typos."
        )
    lookup_row = lookup_row[0]

    # First we check if an overlay with this actor id exists in the heap yet:
    if not np.any(np.logical_and(nodes[:, 1] == 1, nodes[:, 3] == actor_id)):
        # if the allocation type == 0, add it to the heap:
        if lookup_row[3] == 0:
            ovl_size = lookup_row[1]
            nodes = allocate(nodes, actor_id, 1, ovl_size, -1)

    # Now we allocate the instance:
    inst_size = lookup_row[2]
    nodes = allocate(nodes, actor_id, 2, inst_size, dal_timer)

    return nodes
Exemplo n.º 3
0
def save_actorset(acs, version):
    """
    save the given actorset to a file in "actorset_dump"
    """
    dir_path = 'actorset_dump'
    if not os.path.exists(dir_path):
        os.makedirs(dir_path)

    versions = [
        "OoT_NTSC_1.0", "OoT_NTSC_1.1", "OoT_NTSC_1.2", "OoT_PAL_1.0",
        "OoT_PAL_1.1", "OoT_U_GC", "OoT_E_GC", "OoT_J_GC", "OoT_U_MQ",
        "OoT_E_MQ", "OoT_J_MQ", "MM_J_1.0", "MM_J_1.1", "MM_U_1.0",
        "MM_PAL_1.0", "MM_PAL_1.1", "MM_GC_J", "MM_GC_U", "MM_GC_E"
    ]

    # Make folders if they don't exist
    for v in versions:
        if not os.path.exists(dir_path + '\\' + v):
            os.makedirs(dir_path + '\\' + v)

    path = None
    # Make folders if they don't exist
    for v in versions:
        if not os.path.exists(dir_path + '\\' + v):
            os.makedirs(dir_path + '\\' + v)

    # Get the version directory
    for v in versions:
        if str.lower(version) == str.lower(v):
            path = dir_path + '\\' + v
            break

    # Invalid version?
    if path == None:
        sys.exit("No valid version has been given in 'actorset.txt'.")

    # The number to give the file will be the number of files in the directory at the time.
    file_num = len(os.listdir(str(path)))

    # Start writing the actor sets out
    with open(path + "\\actorset" + str(file_num) + ".txt", 'w+') as the_file:
        the_file.write("version:" + version + "\n\n")
        for i in range(len(acs)):
            the_file.write("Step " + str(i) + "\n")
            for j in range(len(acs[i])):
                the_file.write(
                    t.get_hex(acs[i][j, 0], 4) + "," + str(acs[i][j, 1]) +
                    "\n")
            the_file.write('\n')
    return
Exemplo n.º 4
0
def display_heap(nodes, show_nodes=False):
    # Loop through until we've displayed all entities.
    this_idx = 0
    display_completed = False
    while not display_completed:

        # Unpack properties about this node
        this_addr = nodes[this_idx, 0]
        this_type = nodes[this_idx, 1]
        this_id = nodes[this_idx, 3]

        # Get the index of the next node
        next_idx = nodes[this_idx, 5]

        # If we want to show nodes:
        if show_nodes:
            ad = ('0x{:06X}').format(this_addr)
            print(ad, "NODE", t.get_hex(nodes[this_idx, 2], 4))

        # If we're at the final node, stop:
        if next_idx == -1:
            display_completed = True
            break

        # If we're not at the final node, print the proceeding instance/ovl
        else:
            if this_type == 1:
                ad_str = ('0x{:06X}').format(this_addr + node_size)
                id_str = ('0x{:04X}').format(this_id)
                print(ad_str, id_str, "OVERLAY")
            elif this_type == 2:
                ad_str = ('0x{:06X}').format(this_addr + node_size)
                id_str = ('0x{:04X}').format(this_id)
                print(ad_str, id_str, "INSTANCE")

        # Prepare to proceed to next node
        this_idx = next_idx
    print()
    return
Exemplo n.º 5
0
def solution_finder(acset):
    # This is for modifying all the data randomly until we get a result that we want.
    acpool, actor1_id, actor2_id, actor1_step, actor2_step, offset = io.get_actorpool(
        acset)
    num_sets = len(acset)

    # Loop, keep finding solutions.
    while True:
        acs = acset
        acp = np.array(acpool)

        # For each step, see if we have actors in the pool
        for i in range(num_sets):
            this_acp = acp[acp[:, 0] == i]
            num_actors = len(this_acp)
            # If we do,
            if num_actors != 0:
                # Empty the set
                acs[i] = np.array([[]])
                # Pick a random actors
                idx = t.pick_random(num_actors)
                actors = this_acp[idx]
                # Add each one to the actorset according to their rules.
                for j in range(len(actors)):
                    actor_id = actors[j, 1]
                    timer1 = actors[j, 2]
                    timer2 = actors[j, 3]
                    if actor_id == bugs_id:
                        # Spawn 3 bugs:
                        for k in range(3):
                            acs[i] = add_from_pool(acs[i], actor_id, timer1)
                    elif actor_id == bf_id:
                        # Spawn 19 blue fire:
                        if timer2 == EMPTY_ID:
                            for k in range(19):
                                acs[i] = add_from_pool(acs[i], actor_id,
                                                       timer1)
                        else:
                            acs[i] = add_from_pool(acs[i], actor_id, timer2)
                            for k in range(8):
                                acs[i] = add_from_pool(acs[i], actor_id,
                                                       timer1)
                            for k in range(10):
                                acs[i] = add_from_pool(acs[i], actor_id,
                                                       timer2)
                    else:
                        acs[i] = add_from_pool(acs[i], actor_id, timer1)
                # if the set is still empty, replace it with an empty list []
                if np.size(acs[i]) == 0:
                    acs[i] = []

        # Run the main simulation and get the positions of the deisred actors:
        actor1_pos, actor2_pos = main(acs, False, actor1_id, actor2_id,
                                      actor1_step, actor2_step)

        # Find if any of the sets of found actors are the desired offset away:
        POS1, POS2 = np.meshgrid(actor1_pos, actor2_pos)
        print(t.get_hex(actor1_pos), t.get_hex(actor2_pos))
        print(t.get_hex(POS2 - POS1))
        print()
        if np.any(POS2 - POS1 == offset):
            print("SOLUTION FOUND")
            io.save_actorset(acs, version)
Exemplo n.º 6
0
def solution_finder(acset, labels):
    # This is for modifying all the data randomly until we get a result that we want.
    acpool, actor1_id, actor2_id, actor1_step, actor2_step, offset = io.get_actorpool(
        acset)
    num_sets = len(acset)

    # Loop, keep finding solutions.
    while True:
        acs = acset
        acp = np.array(acpool)

        # For each step, see if we have actors in the pool
        for i in range(num_sets):
            this_acp = acp[acp[:, 0] == i]
            num_actors = len(this_acp)
            # If we do,
            if num_actors != 0:
                # Empty the set
                acs[i] = np.array([[]])
                # Pick a random actors
                idx = t.pick_random(num_actors)
                actors = this_acp[idx]
                # Cap at three explosives
                explosive_counter = 0
                # Add each one to the actorset according to their rules.
                for j in range(len(actors)):
                    actor_id = actors[j, 1]
                    timer1 = actors[j, 2]
                    timer2 = actors[j, 3]
                    if actor_id == bombs_id or actor_id == bombchus_id:
                        explosive_counter = explosive_counter + 1
                        if explosive_counter > EXPLOSIVE_LIMIT:
                            continue
                    if actor_id == bugs_id:
                        # Spawn 3 bugs:
                        for k in range(3):
                            acs[i] = add_from_pool(acs[i], actor_id, timer1)
                    elif actor_id == bf_id:
                        # Spawn 19 blue fire:
                        if timer2 == EMPTY_ID:
                            for k in range(19):
                                acs[i] = add_from_pool(acs[i], actor_id,
                                                       timer1)
                        else:
                            acs[i] = add_from_pool(acs[i], actor_id, timer2)
                            for k in range(8):
                                acs[i] = add_from_pool(acs[i], actor_id,
                                                       timer1)
                            for k in range(10):
                                acs[i] = add_from_pool(acs[i], actor_id,
                                                       timer2)
                    else:
                        acs[i] = add_from_pool(acs[i], actor_id, timer1)
                # if the set is still empty, replace it with an empty list []
                if np.size(acs[i]) == 0:
                    acs[i] = []
            # Randomly fill in labels
            # need_to_convert = False
            # for idx in range(len(acs[i])):
            #    if acs[i][idx][1] in labels:
            #        need_to_convert = True
            #        acs[i][idx][1] = int(choice(labels[acs[i][idx][1]]))
            # if need_to_convert:
            #    acs[i] = [[int(numeric_string[0]),int(numeric_string[1])] for numeric_string in acs[i]]

        # Run the main simulation and get the positions of the deisred actors:
        # print(acs)
        actor1_pos, actor2_pos = main(copy.deepcopy(acs), labels, False, False,
                                      actor1_id, actor2_id, actor1_step,
                                      actor2_step)

        # Find if any of the sets of found actors are the desired offset away:
        POS1, POS2 = np.meshgrid(actor1_pos, actor2_pos)
        print(t.get_hex(actor1_pos), t.get_hex(actor2_pos))
        print(t.get_hex(POS2 - POS1))
        print()
        if np.any(POS2 - POS1 == offset):
            print("SOLUTION FOUND")
            print("actor1_id: ", actor1_id)
            print("actor2_id: ", actor2_id)
            print("actor1_pos: ", actor1_pos)
            print("actor2_pos: ", actor2_pos)
            print("offset: ", offset)
            print("POS1: ", POS1)
            print("POS2: ", POS2)
            print(acs)
            io.save_actorset(acs, version)
            sys.exit("Found a solution, guess I'll die")