コード例 #1
0
 def read_files(self):
     """Reads files."""
     self.roms = []
     files = self.get_files()
     num_files = len(files)
     for filenum, filename in enumerate(files):
         fullpath = os.path.join(self.rom_path, filename)
         try:
             archive = Archive(fullpath)
             for fname in archive.namelist:
                 rom_header = m64p_rom_header()
                 ctypes.memmove(
                     ctypes.byref(rom_header),
                     archive.read(fname, ctypes.sizeof(rom_header)),
                     ctypes.sizeof(rom_header))
                 rom_settings = self.parent.core.get_rom_settings(
                     sl(rom_header.CRC1), sl(rom_header.CRC2))
                 if rom_settings:
                     crc = "%X%X" % (sl(rom_header.CRC1), sl(rom_header.CRC2))
                     self.roms.append((crc, rom_settings.goodname, fullpath, fname))
             archive.close()
         except Exception, err:
             log.warn(str(err))
             continue
         percent = float(filenum) / float(num_files) * 100
         self.parent.progressBar.emit(SIGNAL("valueChanged(int)"), percent)
コード例 #2
0
 def read_files(self):
     """Reads files."""
     self.roms = []
     files = self.get_files()
     num_files = len(files)
     for filenum, filename in enumerate(files):
         fullpath = os.path.join(self.rom_path, filename)
         try:
             archive = Archive(fullpath)
             for fname in archive.namelist:
                 rom_header = m64p_rom_header()
                 ctypes.memmove(
                     ctypes.byref(rom_header),
                     archive.read(fname, ctypes.sizeof(rom_header)),
                     ctypes.sizeof(rom_header))
                 rom_settings = self.parent.core.get_rom_settings(
                     sl(rom_header.CRC1), sl(rom_header.CRC2))
                 if rom_settings:
                     crc = "%X%X" % (sl(rom_header.CRC1), sl(
                         rom_header.CRC2))
                     self.roms.append(
                         (crc, rom_settings.goodname, fullpath, fname))
             archive.close()
         except Exception, err:
             log.warn(str(err))
             continue
         percent = float(filenum) / float(num_files) * 100
         self.parent.progressBar.emit(SIGNAL("valueChanged(int)"), percent)
コード例 #3
0
 def __init__(self, parent=None):
     self.parent = parent
     self.core = self.parent.worker.core
     rom_info = [('GoodName', self.core.rom_settings.goodname.decode()),
                 ('Name', self.core.rom_header.Name.decode()),
                 ('MD5', self.core.rom_settings.MD5.decode()),
                 ('CRC1', '%x' % sl(self.core.rom_header.CRC1)),
                 ('CRC2', '%x' % sl(self.core.rom_header.CRC2)),
                 ('Type', self.core.rom_type),
                 ('Size', self.get_rom_size()),
                 ('Country', self.get_country_name()),
                 ('Manufacturer', self.get_manufacturer())]
     info = os.linesep.join(
         [k + ': ' + str(v) for k, v in rom_info if str(v)])
     QMessageBox.information(self.parent, 'ROM Information', info)
コード例 #4
0
 def __init__(self, parent=None):
     self.parent = parent
     self.core = self.parent.worker.core
     rom_info = [
         ('GoodName', self.core.rom_settings.goodname),
         ('Name', self.core.rom_header.Name),
         ('MD5', self.core.rom_settings.MD5),
         ('CRC1', '%x' % sl(self.core.rom_header.CRC1)),
         ('CRC2', '%x' % sl(self.core.rom_header.CRC2)),
         ('Type', self.core.rom_type),
         ('Size', self.get_rom_size()),
         ('Country', self.get_country_name()),
         ('Manufacturer', self.get_manufacturer())
     ]
     info = os.linesep.join([k+': '+str(v) for k, v in rom_info if str(v)])
     QMessageBox.information(self.parent, 'ROM Information', info)
コード例 #5
0
ファイル: worker.py プロジェクト: V1del/mupen64plus-ui-python
 def save_image(self, title=True):
     """Saves snapshot or title image."""
     data_path = self.core.config.get_path("UserData")
     capture = "title" if title else "snapshot"
     dst_path = os.path.join(data_path, capture)
     if not os.path.isdir(dst_path):
         os.makedirs(dst_path)
     screenshot = self.get_screenshot(os.path.join(data_path, "screenshot"))
     if screenshot:
         image_name = "%X%X.png" % (sl(
             self.core.rom_header.CRC1), sl(self.core.rom_header.CRC2))
         try:
             shutil.copyfile(screenshot, os.path.join(dst_path, image_name))
             log.info("Captured %s" % capture)
         except IOError:
             log.exception("couldn't save image %s" % image_name)
コード例 #6
0
 def save_image(self, title=True):
     """Saves snapshot or title image."""
     data_path = self.core.config.get_path("UserData")
     capture = "title" if title else "snapshot"
     dst_path = os.path.join(data_path, capture)
     if not os.path.isdir(dst_path):
         os.makedirs(dst_path)
     screenshot = self.get_screenshot(
         os.path.join(data_path, "screenshot"))
     if screenshot:
         image_name = "%X%X.png" % (
             sl(self.core.rom_header.CRC1), sl(self.core.rom_header.CRC2))
         try:
             shutil.copyfile(screenshot, os.path.join(dst_path, image_name))
             log.info("Captured %s" % capture)
         except IOError:
             log.exception("couldn't save image %s" % image_name)
コード例 #7
0
    def get_rom_crc(self, archive, fname):
        rom_header = m64p_rom_header()
        ctypes.memmove(
            ctypes.byref(rom_header),
            archive.read(fname, ctypes.sizeof(rom_header)),
            ctypes.sizeof(rom_header))
        crc1_pre = sl(rom_header.CRC1)
        crc2_pre = sl(rom_header.CRC2)

        regs = 0
        regs |= rom_header.init_PI_BSB_DOM1_LAT_REG << 24
        regs |= rom_header.init_PI_BSB_DOM1_PGS_REG << 16
        regs |= rom_header.init_PI_BSB_DOM1_PWD_REG << 8
        regs |= rom_header.init_PI_BSB_DOM1_PGS_REG2

        if regs == 0x80371240:
            # native *.z64
            crc1 = crc1_pre
            crc2 = crc2_pre
        elif regs == 0x37804012:
            # byteswapped [BADC] *.v64
            crc1 = 0
            crc1 |= ((crc1_pre >> 0) & 0xff) << 8
            crc1 |= ((crc1_pre >> 8) & 0xff) << 0
            crc1 |= ((crc1_pre >> 16) & 0xff) << 24
            crc1 |= ((crc1_pre >> 24) & 0xff) << 16
            crc2 = 0
            crc2 |= ((crc2_pre >> 0) & 0xff) << 8
            crc2 |= ((crc2_pre >> 8) & 0xff) << 0
            crc2 |= ((crc2_pre >> 16) & 0xff) << 24
            crc2 |= ((crc2_pre >> 24) & 0xff) << 16
        elif regs == 0x40123780:
            # wordswapped [DCBA] *.n64
            crc1 = 0
            crc1 |= ((crc1_pre >> 0) & 0xff) << 24
            crc1 |= ((crc1_pre >> 8) & 0xff) << 16
            crc1 |= ((crc1_pre >> 16) & 0xff) << 8
            crc1 |= ((crc1_pre >> 24) & 0xff) << 0
            crc2 = 0
            crc2 |= ((crc2_pre >> 0) & 0xff) << 24
            crc2 |= ((crc2_pre >> 8) & 0xff) << 16
            crc2 |= ((crc2_pre >> 16) & 0xff) << 8
            crc2 |= ((crc2_pre >> 24) & 0xff) << 0
        else:
            return None
        return (crc1, crc2)
コード例 #8
0
 def get_manufacturer(self):
     if chr(sl(self.core.rom_header.Manufacturer_ID)) == 'N':
         return 'Nintendo'
     else:
         return '0x%x' % self.core.rom_header.Manufacturer_ID
コード例 #9
0
    def read_file(self):
        """Parses cheats file"""
        rom_found = False
        cheat_name = None
        cheat_description = None
        cheat_gamename = None
        cheat_codes = []

        cheat_file = os.path.join(
            self.parent.worker.core.config.get_path("SharedData"),
            'mupencheat.txt')
        if not os.path.isfile(cheat_file) or not os.access(
                cheat_file, os.R_OK):
            log.warn("cheat code database file '%s' not found." % cheat_file)
            return None

        rom_section = "%08X-%08X-C:%X" % (
            sl(self.parent.worker.core.rom_header.CRC1),
            sl(self.parent.worker.core.rom_header.CRC2),
            self.parent.worker.core.rom_header.Country_code & 0xff)
        rom_section = rom_section.upper()

        code_re = re.compile('^([0-9A-F]{8})\s+([?|0-9A-F]{4})\s?(.*)$', re.M)

        try:
            fd = open(cheat_file, 'r')
        except IOError:
            log.warn("couldn't open cheat code database file '%s'." %
                     cheat_file)
            return None
        else:
            lines = [line.strip() for line in fd.readlines()]
            fd.close()

        for line in lines:
            # ignore line if comment
            if line.startswith('#') or line.startswith('//'):
                continue

            # handle beginning of new rom section
            if line.startswith('crc '):
                # if we have already found cheats for the given ROM file
                # then return cheats and exit upon encountering a new ROM section
                if rom_found and (cheat_codes or cheat_gamename is not None):
                    del lines
                    return cheat_codes
                # else see if this section matches
                if line[4:] == rom_section:
                    rom_found = True
                continue

            # if we haven't found the specified section
            # then continue looking
            if not rom_found:
                continue

            # game name
            if line.startswith('gn '):
                cheat_gamename = line[3:]
                continue

            # code name
            if line.startswith('cn '):
                cheat_name = line[3:]
                continue

            # if cheat_name is empty don't do these checks
            if not cheat_name:
                continue

            # code description
            if line.startswith('cd '):
                cheat_description = line[3:]
                continue

            # match cheat codes
            match = code_re.match(line)
            if match:
                c1 = match.group(1)
                c2 = match.group(2)
                if '??' in c2:
                    c3 = [
                        tuple(item.split(':'))
                        for item in match.group(3).split(',')
                    ]
                else:
                    c3 = None
                cheat_codes.append((cheat_name, cheat_description, c1, c2, c3))
                if cheat_description:
                    cheat_description = None
                continue

            if line:
                # otherwise we don't know what this line is
                log.warn("unrecognized line in cheat file: '%s'" % line)
        return None
コード例 #10
0
 def get_manufacturer(self):
     if chr(sl(self.core.rom_header.Manufacturer_ID)) == 'N':
         return 'Nintendo'
     else:
         return '0x%x' % self.core.rom_header.Manufacturer_ID
コード例 #11
0
    def read_file(self):
        """Parses cheats file"""
        rom_found = False
        cheat_name = None
        cheat_description = None
        cheat_gamename = None
        cheat_codes = []

        cheat_file = os.path.join(
            self.parent.worker.core.config.get_path( "SharedData"), 'mupencheat.txt')
        if not os.path.isfile(cheat_file) or not os.access(cheat_file, os.R_OK):
            log.warn("cheat code database file '%s' not found." % cheat_file)
            return None

        rom_section = "%08X-%08X-C:%X" % (
            sl(self.parent.worker.core.rom_header.CRC1),
            sl(self.parent.worker.core.rom_header.CRC2),
            self.parent.worker.core.rom_header.Country_code & 0xff)
        rom_section = rom_section.upper()

        code_re = re.compile('^([0-9A-F]{8})\s+([?|0-9A-F]{4})\s?(.*)$', re.M)

        try:
            fd = open(cheat_file, 'r')
        except IOError:
            log.warn("couldn't open cheat code database file '%s'." % cheat_file)
            return None
        else:
            lines = [line.strip() for line in fd.readlines()]
            fd.close()

        for line in lines:
            # ignore line if comment
            if line.startswith('#') or line.startswith('//'):
                continue

            # handle beginning of new rom section
            if line.startswith('crc '):
                # if we have already found cheats for the given ROM file
                # then return cheats and exit upon encountering a new ROM section
                if rom_found and (cheat_codes or cheat_gamename is not None):
                    del lines
                    return cheat_codes
                # else see if this section matches
                if line[4:] == rom_section:
                    rom_found = True
                continue

            # if we haven't found the specified section
            # then continue looking
            if not rom_found:
                continue

            # game name
            if line.startswith('gn '):
                cheat_gamename = line[3:]
                continue

            # code name
            if line.startswith('cn '):
                cheat_name = line[3:]
                continue

            # if cheat_name is empty don't do these checks
            if not cheat_name:
                continue

            # code description
            if line.startswith('cd '):
                cheat_description = line[3:]
                continue

            # match cheat codes
            match = code_re.match(line)
            if match:
                c1 = match.group(1)
                c2 = match.group(2)
                if '??' in c2:
                    c3 = [tuple(item.split(':')) for item in match.group(3).split(',')]
                else:
                    c3 = None
                cheat_codes.append(
                        (cheat_name, cheat_description, c1, c2, c3))
                if cheat_description:
                    cheat_description = None
                continue

            if line:
                # otherwise we don't know what this line is
                log.warn("unrecognized line in cheat file: '%s'" % line)
        return None