def writeToRom(self, rom): for ipsDescFname in [s for s in os.listdir( 'resources/ips/' + rom.type()) if s.lower().endswith(".yml")]: patchName = ipsDescFname[:-4] with open('resources/ips/' + rom.type() + '/' + ipsDescFname) as ipsDescFile: ipsDesc = yaml.load(ipsDescFile, Loader=yaml.CSafeLoader) if ((ipsDesc["Title"] in self._patches) and (self._patches[ipsDesc["Title"]].lower() == "enabled")): ranges = map(lambda y: tuple(map(lambda z: int(z, 0), y[1:-1].split(','))), ipsDesc["Ranges"]) # First, check that we can apply this for range in ranges: if not rom.isRangeFree(range): # Range is not free, can't apply raise RuntimeError("Can't apply patch \"" + ipsDesc["Title"] + "\", range (" + hex(range[0]) + "," + hex(range[1]) + ") is not free") # Now apply the patch patchName = ipsDescFname[:-4] ips = Ips() offset = 0 if "Header" in ipsDesc: offset = ipsDesc["Header"] ips.load('resources/ips/' + rom.type() + '/' + patchName + '.ips', offset) ips.apply(rom) # Mark the used ranges as used for range in ranges: rom.markRangeAsNotFree(range) updateProgress(50)
def readFromRom(self, rom): self._patches = dict() # Loop through all the patches for this romtyp for ipsDescFname in [s for s in os.listdir( 'resources/ips/' + rom.type()) if s.lower().endswith(".yml")]: patchName = ipsDescFname[:-4] ips = Ips() ips.load('resources/ips/' + rom.type() + '/' + patchName + '.ips') with open('resources/ips/' + rom.type() + '/' + ipsDescFname) as ipsDescFile: ipsDesc = yaml.load(ipsDescFile, Loader=yaml.CSafeLoader) if ipsDesc["Auto-Apply"]: self._patches[ipsDesc["Title"]] = "enabled" else: self._patches[ipsDesc["Title"]] = "disabled" updateProgress(50)