コード例 #1
0
ファイル: gui.py プロジェクト: Lyrositor/CoilSnake
    def do_compile(self, project_entry, base_rom_entry, rom_entry):
        base_rom = base_rom_entry.get()
        rom = rom_entry.get()
        project = project_entry.get()

        if base_rom and rom and project:
            self.save_default_tab()

            base_rom_rom = Rom()
            base_rom_rom.from_file(base_rom)
            if base_rom_rom.type == "Earthbound" and len(base_rom_rom) == 0x300000:
                confirm = tkMessageBox.askquestion("Expand Your Base ROM?",
                                                   "You are attempting to compile using a base ROM which is "
                                                   "unexpanded. It is likely that this will not succeed, as CoilSnake "
                                                   "needs the extra space in an expanded ROM to store additional data."
                                                   "\n\n"
                                                   "Would you like to expand this base ROM before proceeding? This "
                                                   "will permanently overwrite your base ROM.",
                                                   icon='warning')
                if confirm == "yes":
                    base_rom_rom.expand(0x400000)
                    base_rom_rom.to_file(base_rom)
            del base_rom_rom

            # Update the GUI
            self.console.clear()
            self.disable_all_components()

            self.progress_bar.clear()

            log.info("Starting compilation...")

            thread = Thread(target=self._do_compile_help, args=(project, base_rom, rom))
            thread.start()
コード例 #2
0
ファイル: gui_util.py プロジェクト: Lyrositor/CoilSnake
def expand_rom(root, ex=False):
    rom = Rom()
    filename = tkFileDialog.askopenfilename(
        parent=root,
        initialdir=os.path.expanduser("~"),
        title="Select a ROM to expand",
        filetypes=ROM_FILETYPES)
    if filename:
        rom.from_file(filename)
        if (not ex and len(rom) >= 0x400000) or (ex and (len(rom) >= 0x600000)):
            tkMessageBox.showerror(
                parent=root,
                title="Error",
                message="This ROM is already expanded.")
        else:
            if ex:
                rom.expand(0x600000)
            else:
                rom.expand(0x400000)
            rom.to_file(filename)
            del rom
            tkMessageBox.showinfo(
                parent=root,
                title="Expansion Successful",
                message="Your ROM was expanded.")
コード例 #3
0
ファイル: gui.py プロジェクト: john-soklaski/CoilSnake
    def do_compile(self, project_entry, base_rom_entry, rom_entry):
        base_rom = base_rom_entry.get()
        rom = rom_entry.get()
        project = project_entry.get()

        if base_rom and rom and project:
            self.save_default_tab()

            base_rom_rom = Rom()
            base_rom_rom.from_file(base_rom)
            if base_rom_rom.type == "Earthbound" and len(base_rom_rom) == 0x300000:
                confirm = tkinter.messagebox.askquestion("Expand Your Base ROM?",
                                                   "You are attempting to compile using a base ROM which is "
                                                   "unexpanded. It is likely that this will not succeed, as CoilSnake "
                                                   "needs the extra space in an expanded ROM to store additional data."
                                                   "\n\n"
                                                   "Would you like to expand this base ROM before proceeding? This "
                                                   "will permanently overwrite your base ROM.",
                                                   icon='warning')
                if confirm == "yes":
                    base_rom_rom.expand(0x400000)
                    base_rom_rom.to_file(base_rom)
            del base_rom_rom

            # Update the GUI
            self.console.clear()
            self.disable_all_components()

            self.progress_bar.clear()

            log.info("Starting compilation...")

            thread = Thread(target=self._do_compile_help, args=(project, base_rom, rom))
            thread.start()
コード例 #4
0
def expand_rom(root, ex=False):
    rom = Rom()
    filename = tkFileDialog.askopenfilename(
        parent=root,
        initialdir=os.path.expanduser("~"),
        title="Select a ROM to expand",
        filetypes=ROM_FILETYPES)
    if filename:
        rom.from_file(filename)
        if (not ex and len(rom) >= 0x400000) or (ex and (len(rom) >= 0x600000)):
            tkMessageBox.showerror(
                parent=root,
                title="Error",
                message="This ROM is already expanded.")
        else:
            if ex:
                rom.expand(0x600000)
            else:
                rom.expand(0x400000)
            rom.to_file(filename)
            del rom
            tkMessageBox.showinfo(
                parent=root,
                title="Expansion Successful",
                message="Your ROM was expanded.")
コード例 #5
0
ファイル: common.py プロジェクト: LittleCube13/CoilSnake
def patch_rom(clean_rom_filename, patched_rom_filename, patch_filename, headered, progress_bar=None):
    if not os.path.isfile(clean_rom_filename):
        raise RuntimeError("Clean Rom \"" + clean_rom_filename + "\" is not a file.")
    if not os.path.isfile(patch_filename):
        raise RuntimeError("Patch \"" + patch_filename + "\" is not a file.")

    if clean_rom_filename != patched_rom_filename:
        copyfile(clean_rom_filename, patched_rom_filename)

    log.info("Patching ROM {} with patch {}".format(patched_rom_filename, patch_filename))
    patching_start_time = time.time()

    if patch_filename.endswith(".ips"):
        output_rom = Rom()
        output_rom.from_file(clean_rom_filename)
        patch = IpsPatch()
    elif patch_filename.endswith(".ebp"):
        output_rom = EbRom()
        output_rom.from_file(clean_rom_filename)
        patch = EbpPatch()
    else:
        raise CoilSnakeError("Unknown patch format.")

    # Load the patch and expand the ROM as needed
    add_header = headered and not isinstance(patch, EbpPatch)
    extra = int(add_header)*0x200  # 0x200 if a header will be added, 0 otherwise
    patch.load(patch_filename)
    if isinstance(patch, EbpPatch):
        log.info("Patch: {title} by {author}".format(**patch.metadata))
    if patch.last_offset_used > len(output_rom) + extra:
        if patch.last_offset_used < 0x400000 + extra:
            output_rom.expand(0x400000)
        elif patch.last_offset_used < 0x600000 + extra:
            output_rom.expand(0x600000)
        else:
            output_rom.expand(patch.last_offset_used)

    # If the user specified the patch was made for a headered ROM, add a header
    # to the ROM
    if add_header:
        output_rom.add_header()

    # Apply the patch and write out the patched ROM
    patch.apply(output_rom)
    if add_header:
        # Remove the header that was added, so that we're always dealing with
        # unheadered ROMs in the end
        output_rom.data = output_rom.data[0x200:]
        output_rom.size -= 0x200
    output_rom.to_file(patched_rom_filename)

    log.info("Patched to {} in {:.2f}s".format(patched_rom_filename, time.time() - patching_start_time))
コード例 #6
0
def patch_rom(clean_rom_filename, patched_rom_filename, patch_filename, headered, progress_bar=None):
    if not os.path.isfile(clean_rom_filename):
        raise RuntimeError("Clean Rom \"" + clean_rom_filename + "\" is not a file.")
    if not os.path.isfile(patch_filename):
        raise RuntimeError("Patch \"" + patch_filename + "\" is not a file.")

    if clean_rom_filename != patched_rom_filename:
        copyfile(clean_rom_filename, patched_rom_filename)

    log.info("Patching ROM {} with patch {}".format(patched_rom_filename, patch_filename))
    patching_start_time = time.time()

    if patch_filename.endswith(".ips"):
        output_rom = Rom()
        output_rom.from_file(clean_rom_filename)
        patch = IpsPatch()
    elif patch_filename.endswith(".ebp"):
        output_rom = EbRom()
        output_rom.from_file(clean_rom_filename)
        patch = EbpPatch()
    else:
        raise CoilSnakeError("Unknown patch format.")

    # Load the patch and expand the ROM as needed
    add_header = headered and not isinstance(patch, EbpPatch)
    extra = int(add_header)*0x200  # 0x200 if a header will be added, 0 otherwise
    patch.load(patch_filename)
    if isinstance(patch, EbpPatch):
        log.info("Patch: {title} by {author}".format(**patch.metadata))
    if patch.last_offset_used > len(output_rom) + extra:
        if patch.last_offset_used < 0x400000 + extra:
            output_rom.expand(0x400000)
        elif patch.last_offset_used < 0x600000 + extra:
            output_rom.expand(0x600000)
        else:
            output_rom.expand(patch.last_offset_used)

    # If the user specified the patch was made for a headered ROM, add a header
    # to the ROM
    if add_header:
        output_rom.add_header()

    # Apply the patch and write out the patched ROM
    patch.apply(output_rom)
    if add_header:
        # Remove the header that was added, so that we're always dealing with
        # unheadered ROMs in the end
        output_rom.data = output_rom.data[0x200:]
        output_rom.size -= 0x200
    output_rom.to_file(patched_rom_filename)

    log.info("Patched to {} in {:.2f}s".format(patched_rom_filename, time.time() - patching_start_time))
コード例 #7
0
ファイル: common.py プロジェクト: kashaiahyah85/CoilSnake
def expand(romfile, ex=False):
    rom = Rom()
    rom.from_file(romfile)
    if (not ex and len(rom) >= 0x400000) or (ex and (len(rom) >= 0x600000)):
        return False
    else:
        if ex:
            rom.expand(0x600000)
        else:
            rom.expand(0x400000)
        rom.to_file(romfile)
        del rom
        return True
コード例 #8
0
ファイル: common.py プロジェクト: LittleCube13/CoilSnake
def expand(romfile, ex=False):
    rom = Rom()
    rom.from_file(romfile)
    if (not ex and len(rom) >= 0x400000) or (ex and (len(rom) >= 0x600000)):
        return False
    else:
        if ex:
            rom.expand(0x600000)
        else:
            rom.expand(0x400000)
        rom.to_file(romfile)
        del rom
        return True
コード例 #9
0
ファイル: common.py プロジェクト: Lyrositor/CoilSnake
def compile_project(project_path, base_rom_filename, output_rom_filename, ccscript_offset=None, progress_bar=None):
    modules = load_modules()

    project_filename = os.path.join(project_path, PROJECT_FILENAME)
    project = Project()
    project.load(project_filename)
    check_if_project_too_old(project)
    check_if_project_too_new(project)

    if base_rom_filename != output_rom_filename:
        copyfile(base_rom_filename, output_rom_filename)

    # Compile scripts using CCScript
    script_filenames = [os.path.join(project_path, "ccscript", x)
                        for x in os.listdir(os.path.join(project_path, "ccscript"))
                        if x.lower().endswith('.ccs')]

    if script_filenames:
        log.info("Compiling CCScript")
        if not ccscript_offset:
            ccscript_offset = "F10000"
        elif type(ccscript_offset) == int:
            ccscript_offset = "{:x}".format(ccscript_offset)

        ccc_args = ["-n",
                    "--libs", ccscript_library_path(),
                    "--summary", os.path.join(project_path, "ccscript", "summary.txt"),
                    "-s", ccscript_offset,
                    "-o", output_rom_filename] + script_filenames
        ccc_returncode, ccc_log = ccc(ccc_args)

        if ccc_returncode == 0:
            log.info("Finished compiling CCScript")
        else:
            raise CCScriptCompilationError("CCScript compilation failed with output:\n" + ccc_log)

    rom = Rom()
    rom.from_file(output_rom_filename)
    check_if_types_match(project=project, rom=rom)

    compatible_modules = [(name, clazz) for name, clazz in modules if clazz.is_compatible_with_romtype(rom.type)]
    tick_amount = 1.0/(2*len(compatible_modules))

    log.info("Compiling Project {}".format(project_path))
    compile_start_time = time.time()

    for module_name, module_class in modules:
        if module_class.is_compatible_with_romtype(rom.type):
            for free_range in module_class.FREE_RANGES:
                rom.deallocate(free_range)

    for module_name, module_class in modules:
        if not module_class.is_compatible_with_romtype(rom.type):
            continue

        log.info("Compiling {}...".format(module_class.NAME))
        start_time = time.time()
        with module_class() as module:
            module.read_from_project(lambda x, y: project.get_resource(module_name, x, y, 'rb'))
            if progress_bar:
                progress_bar.tick(tick_amount)
            module.write_to_rom(rom)
            if progress_bar:
                progress_bar.tick(tick_amount)
        log.info("Finished compiling {} in {:.2f}s".format(module_class.NAME, time.time() - start_time))

    log.debug("Saving ROM")
    rom.to_file(output_rom_filename)

    log.info("Compiled to {} in {:.2f}s, finished at {}".format(
        output_rom_filename, time.time() - compile_start_time, datetime.now().strftime('%I:%M:%S %p')))
コード例 #10
0
ファイル: common.py プロジェクト: kashaiahyah85/CoilSnake
def compile_project(project_path,
                    base_rom_filename,
                    output_rom_filename,
                    ccscript_offset=None,
                    progress_bar=None):
    if not os.path.isdir(project_path):
        raise RuntimeError("Project directory \"" + project_path +
                           "\" is not a directory.")
    if not os.path.isfile(base_rom_filename):
        raise RuntimeError("Base Rom \"" + base_rom_filename +
                           "\" is not a file.")

    modules = load_modules()

    project_filename = os.path.join(project_path, PROJECT_FILENAME)
    project = Project()
    project.load(project_filename)
    check_if_project_too_old(project)
    check_if_project_too_new(project)

    if base_rom_filename != output_rom_filename:
        copyfile(base_rom_filename, output_rom_filename)

    # Compile scripts using CCScript
    script_filenames = [
        os.path.join(project_path, "ccscript", x)
        for x in os.listdir(os.path.join(project_path, "ccscript"))
        if x.lower().endswith('.ccs')
    ]

    if script_filenames:
        log.info("Compiling CCScript")
        if not ccscript_offset:
            ccscript_offset = "F10000"
        elif type(ccscript_offset) == int:
            ccscript_offset = "{:x}".format(ccscript_offset)

        ccc_args = [
            "-n", "--libs",
            ccscript_library_path(), "--summary",
            os.path.join(project_path, "ccscript", "summary.txt"), "-s",
            ccscript_offset, "-o", output_rom_filename
        ] + script_filenames
        ccc_returncode, ccc_log = ccc(ccc_args)

        if ccc_returncode == 0:
            log.info("Finished compiling CCScript")
        else:
            raise CCScriptCompilationError(
                "CCScript compilation failed with output:\n" + ccc_log)

    rom = Rom()
    rom.from_file(output_rom_filename)
    check_if_types_match(project=project, rom=rom)

    compatible_modules = [(name, clazz) for name, clazz in modules
                          if clazz.is_compatible_with_romtype(rom.type)]
    tick_amount = 1.0 / (2 * len(compatible_modules))

    log.info("Compiling Project {}".format(project_path))
    compile_start_time = time.time()

    for module_name, module_class in modules:
        if module_class.is_compatible_with_romtype(rom.type):
            for free_range in module_class.FREE_RANGES:
                rom.deallocate(free_range)

    for module_name, module_class in modules:
        if not module_class.is_compatible_with_romtype(rom.type):
            continue

        log.info("Compiling {}...".format(module_class.NAME))
        start_time = time.time()
        with module_class() as module:
            module.read_from_project(
                lambda x, y, astext=False: project.get_resource(
                    module_name, x, y, 'rt' if astext else 'rb', 'utf-8'
                    if astext else None))
            if progress_bar:
                progress_bar.tick(tick_amount)
            module.write_to_rom(rom)
            if progress_bar:
                progress_bar.tick(tick_amount)
        log.info("Finished compiling {} in {:.2f}s".format(
            module_class.NAME,
            time.time() - start_time))

    log.debug("Saving ROM")
    rom.to_file(output_rom_filename)

    log.info("Compiled to {} in {:.2f}s, finished at {}".format(
        output_rom_filename,
        time.time() - compile_start_time,
        datetime.now().strftime('%I:%M:%S %p')))