def handleIps(self, plandoName, romDataJson): romDataJson = self.vars.romData romDataRaw = json.loads(romDataJson) # everything is string in json, cast to int romData = {} for addr in romDataRaw: romData[int(addr)] = int(romDataRaw[addr]) # dict: address -> value, transform it dict: address -> [values] ipsData = {} prevAddr = -0xff curRecord = [] curRecordAddr = -1 for addr in sorted(romData): if addr == prevAddr + 1: curRecord.append(romData[addr]) else: if len(curRecord) > 0: # save current record ipsData[curRecordAddr] = bytearray(curRecord) # start a new one curRecordAddr = addr curRecord = [romData[addr]] prevAddr = addr # save last record ipsData[curRecordAddr] = bytearray(curRecord) # generate ips using the records ipsPatch = IPS_Patch(ipsData) maxSize = ipsPatch.max_size # store ips in the repository ipsPatch.save(os.path.join(ipsBasePath, "{}.ips".format(plandoName))) return maxSize
#!/usr/bin/python3 import sys, os, json # we're in directory 'tools/' we have to update sys.path sys.path.append(os.path.dirname(sys.path[0])) from rom.ips import IPS_Patch elev = IPS_Patch.load("patches/common/ips/elevators_speed.ips") doors = IPS_Patch.load("patches/common/ips/fast_doors.ips") merged = IPS_Patch() merged.append(elev) merged.append(doors) merged.save("patches/common/ips/elevators_doors_speed.ips")
vanilla = sys.argv[1] ipsToReverse = sys.argv[2:] rom = RealROM(vanilla) for ips in ipsToReverse: if ips not in common_patches.patches: ipsPath = os.path.abspath(ips) destDir, destFile = os.path.split(ipsPath) patch = IPS_Patch.load(ips) patchDict = patch.toDict() else: patchDict = common_patches.patches[ips] destDir = sys.path[0] + "/../patches/common/ips" destFile = ips + ".ips" destFile = "remove_" + destFile destPath = os.path.join(destDir, destFile) reversePatchDict = {} for addr, bytez in patchDict.items(): sz = len(bytez) origBytes = [] rom.seek(addr) for i in range(sz): origBytes.append(rom.readByte()) assert len(origBytes) == sz reversePatchDict[addr] = origBytes reversePatch = IPS_Patch(reversePatchDict) reversePatch.save(destPath) rom.close()
patch = IPS_Patch.load(ips) patch_dict = patch.toDict() # remove overlapping data filtered_dict = {} for keyLow, data in patch_dict.items(): dataLength = len(data) keyHigh = keyLow + dataLength if keyHigh < low or keyLow > high: print("[{}, {}] we have {} bytes of data".format(hex(pc_to_snes(keyLow)), hex(pc_to_snes(keyHigh)), dataLength)) filtered_dict[keyLow] = data else: print("[{}, {}] we have {} bytes of data overlaping with [{}, {}]".format(hex(pc_to_snes(keyLow)), hex(pc_to_snes(keyHigh)), dataLength, hex(pc_to_snes(low)), hex(pc_to_snes(high)))) if len(filtered_dict.keys()) < len(patch_dict.keys()): # write ips split = os.path.split(ips) out = os.path.join(split[0], 'out_'+split[1]) out_patch = IPS_Patch(filtered_dict) out_patch.save(out) print("filtered ips generated: {}".format(out)) else: print("no overlapping record found")