def extractIso(isofile, extractfolder, workfolder=""): common.logMessage("Extracting ISO", isofile, "...") common.makeFolder(extractfolder) common.execute( "wit EXTRACT -o {iso} {folder}".format(iso=isofile, folder=extractfolder), False) if workfolder != "": common.copyFolder(extractfolder, workfolder) common.logMessage("Done!")
def extractRom(romfile, extractfolder, workfolder=""): common.logMessage("Extracting ROM", romfile, "...") ndstool = common.bundledExecutable("ndstool.exe") if not os.path.isfile(ndstool): common.logError("ndstool not found") return common.makeFolder(extractfolder) common.execute(ndstool + " -x {rom} -9 {folder}arm9.bin -7 {folder}arm7.bin -y9 {folder}y9.bin -y7 {folder}y7.bin -t {folder}banner.bin -h {folder}header.bin -d {folder}data -y {folder}overlay". format(rom=romfile, folder=extractfolder), False) if workfolder != "": common.copyFolder(extractfolder, workfolder) common.logMessage("Done!")
def repack(no_rom, dat, bin, img, wsb, sub, no_redirect, force): all = not sub and not dat and not bin and not img and not wsb firstgame = nds.getHeaderID(headerfile) == "YU5J2J" if all or dat: import repack_dat repack_dat.run(firstgame, no_redirect) if all or dat or bin: import repack_bin repack_bin.run(firstgame) if all or wsb: import repack_wsb repack_wsb.run(firstgame) if all or dat or sub: import repack_sub repack_sub.run(firstgame) if all or img: ncgrfolder = "data/repack/data/graphic/" if firstgame else "data/repack/data/graphics/" ncgrfolderin = ncgrfolder.replace("repack", "extract") common.copyFolder(ncgrfolderin, ncgrfolder) nitro.repackIMG("data/work_IMG/", ncgrfolderin, ncgrfolder, ".NCGR", game.readImage) if not firstgame: import repack_kbg repack_kbg.run() # Part of the AP patch with common.Stream(ncgrfolder + "doubleinfo/SDLawrence_01.NCGR", "rb+") as f: f.seek(0x26f1) f.writeByte(0x17) if not no_rom: if os.path.isdir(replacefolder): common.mergeFolder(replacefolder, outfolder) if force != "": if not force.endswith(".wsb"): force += ".wsb" if firstgame: common.copyFile( outfolder + "data/script/" + force, outfolder + "data/script/event/ev_act/act_010_opening.wsb") else: common.copyFile( outfolder + "data/script/" + force, outfolder + "data/script/event/ev_main/main_010_prologue.wsb") subtitle = "My Year with Holo" if firstgame else "The Wind that Spans the Sea" nds.editBannerTitle( bannerfile, "Spice & Wolf\n" + subtitle + "\nASCII MEDIA WORKS") romf = romfile if os.path.isfile(romfile) else romfile.replace( "holo", "holo2") romp = rompatch if os.path.isfile(romfile) else rompatch.replace( "holo", "holo2") nds.repackRom(romf, romp, outfolder, patchfile)
def extractIso(isofile, extractfolder, workfolder=""): common.logMessage("Extracting ISO", isofile, "...") common.makeFolder(extractfolder) iso = pycdlib.PyCdlib() iso.open(isofile) for dirname, dirlist, filelist in iso.walk(iso_path="/"): common.makeFolders(extractfolder + dirname[1:]) for file in filelist: with open(extractfolder + dirname[1:] + "/" + file, "wb") as f: iso.get_file_from_iso_fp(f, iso_path=dirname + "/" + file) iso.close() if workfolder != "": common.copyFolder(extractfolder, workfolder) common.logMessage("Done!")
def extractBIN(infolder, outfolder, cuefile, data="data/"): common.logMessage("Extracting BIN", cuefile, "...") if not os.path.isfile("psximager\\psxrip.exe"): common.logError("psximager not found") return common.clearFolder(infolder) common.execute( "psximager\\psxrip.exe \"{iso}\" \"{folder}\"".format( iso=cuefile, folder=infolder[:-1]), False) common.copyFile(data + "extract.sys", data + "repack.sys") with open(data + "extract.cat", "r") as fin: with open(data + "repack.cat", "w") as fout: fout.write(fin.read().replace(data + "extract", data + "repack")) common.copyFolder(infolder, outfolder) common.logMessage("Done!")
def extractRom(romfile, extractfolder, workfolder="", banksize=0x4000): common.logMessage("Extracting ROM", romfile, "...") common.makeFolder(extractfolder) filesize = os.path.getsize(romfile) banknum = filesize // banksize common.logMessage("Extracting", banknum, "banks ...") with common.Stream(romfile, "rb") as f: for i in range(banknum): bankname = "bank_" if i < 0x10: bankname += "0" bankname += format(i, 'x') with common.Stream(extractfolder + bankname + ".bin", "wb") as fout: fout.write(f.read(banksize)) if workfolder != "": common.copyFolder(extractfolder, workfolder) common.logMessage("Done!")
def extract(rom, bin, tdg, kpc, spc, vsc, yce): all = not rom and not bin and not tdg and not kpc and not spc and not vsc and not yce if all or rom: nds.extractRom(romfile, infolder, outfolder) # Extract NFP archives nfpin = "data/extract/data/" nfpout = "data/extract_NFP/" nfpwork = "data/work_NFP/" common.logMessage("Extracting NFP ...") common.makeFolder(nfpout) files = common.getFiles(nfpin, ".NFP") for file in common.showProgress(files): common.logDebug("Processing", file, "...") common.makeFolder(nfpout + file) with common.Stream(nfpin + file, "rb") as f: f.seek(52) # Header: NFP2.0 (c)NOBORI 1997-2006 filenum = f.readInt() f.seek(4, 1) # Always 0x50 datastart = f.readInt() f.seek(16, 1) # All 0 common.logDebug("Found", filenum, "files, data starting at", datastart) for i in range(filenum): # Filenames are always 16 bytes long, padded with 0s subname = f.readString(16) # Read starting position and size (multiplied by 4) startpos = f.readInt() size = f.readInt() // 4 # Extract the file common.logDebug("Extracting", subname, "starting at", startpos, "with size", size) savepos = f.tell() f.seek(startpos) with common.Stream(nfpout + file + "/" + subname, "wb") as newf: newf.write(f.read(size)) f.seek(savepos) # Copy everything to the work folder common.copyFolder(nfpout, nfpwork) common.logMessage("Done! Extracted", len(files), "archives") if all or bin: import extract_bin extract_bin.run() if all or tdg: nitro.extractNSBMD("data/extract_NFP/NFP3D.NFP/", "data/out_3DG/", ".3DG") if all or kpc: import extract_kpc extract_kpc.run() if all or spc: import extract_spc extract_spc.run() if all or vsc: import extract_vsc extract_vsc.run() if all or yce: for i in range(1, 8): common.copyFile( "data/extract_NFP/NFP2D.NFP/AV01_0" + str(i) + ".YCE", "data/extract_NFP/NFP2D.NFP/AV00_0" + str(i) + ".YCE") import extract_yce extract_yce.run()
def run(): infolder = "data/extract_NFP/NFP2D.NFP/" workfolder = "data/work_KPC/" outfolder = "data/work_NFP/NFP2D.NFP/" common.copyFolder(infolder, outfolder) common.logMessage("Repacking KPC from", workfolder, "...") files = common.getFiles(infolder, ".KPC") for file in common.showProgress(files): pngname = file.replace(".KPC", ".png") if not os.path.isfile(workfolder + pngname): common.copyFile(infolder + file, outfolder + file) continue common.logDebug("Processing", file, "...") with common.Stream(infolder + file, "rb") as fin: with common.Stream(outfolder + file, "wb") as f: # Find palette offset fin.seek(9) palcompressed = fin.readByte() == 1 fin.seek(2, 1) width = fin.readUShort() * 8 height = fin.readUShort() * 8 fin.seek(128) palsize = fin.readUInt() paloffset = fin.readUInt() # Read palette fin.seek(paloffset) if palcompressed: paldata = common.decompress(fin, palsize) else: paldata = fin.read(palsize) # Fix transparency for EQ_M0* files since their palette colors 0 and 1 are the same. tiles, maps = game.readMappedImage(workfolder + pngname, width, height, paldata, file.startswith("EQ_M0")) # Copy the header fin.seek(0) f.write(fin.read(192)) # Write map data mapstart = f.tell() for map in maps: mapdata = (map[0] << 12) + (map[1] << 11) + ( map[2] << 10) + map[3] f.writeUShort(mapdata) mapend = f.tell() f.writeByte(0) # Write tile data tilestart = f.tell() for tile in tiles: for i in range(32): index2 = tile[i * 2] index1 = tile[i * 2 + 1] f.writeByte(((index1) << 4) | index2) tileend = f.tell() f.writeByte(0) # Write palette palstart = f.tell() f.write(paldata) palend = f.tell() f.writeByte(0) # Write header data f.seek(9) f.writeByte(0) f.writeByte(0) f.writeByte(0) f.seek(16) f.writeUInt(mapend - mapstart) f.writeUInt(mapstart) f.seek(92) f.writeUInt(tileend - tilestart) f.writeUInt(tilestart) f.seek(128) f.writeUInt(palend - palstart) f.writeUInt(palstart) common.logMessage("Done!")