def generate_rom(): global flags global sourcefile global difficulty global glitch_fixes global fast_move global sense_dpad global lost_worlds global boss_scaler global zeal_end global quick_pendant global locked_chars global tech_list global seed outfile = sourcefile.split(".") outfile = str(outfile[0]) if flags == "": outfile = "%s.%s.sfc"%(outfile,seed) else: outfile = "%s.%s.%s.sfc"%(outfile,flags,seed) size = stat(sourcefile).st_size if size % 0x400 == 0: copyfile(sourcefile, outfile) elif size % 0x200 == 0: print("SNES header detected. Removing header from output file.") f = open(sourcefile, 'r+b') data = f.read() f.close() data = data[0x200:] open(outfile, 'w+').close() f = open(outfile, 'r+b') f.write(data) f.close() print("Applying patch. This might take a while.") bigpatches.write_patch("patch.ips",outfile) patches.patch_file("patches/patch_codebase.txt",outfile) if glitch_fixes == "Y": patches.patch_file("patches/save_anywhere_patch.txt",outfile) patches.patch_file("patches/unequip_patch.txt",outfile) patches.patch_file("patches/fadeout_patch.txt",outfile) patches.patch_file("patches/hp_overflow_patch.txt",outfile) if fast_move == "Y": patches.patch_file("patches/fast_overworld_walk_patch.txt",outfile) patches.patch_file("patches/faster_epoch_patch.txt",outfile) if sense_dpad == "Y": patches.patch_file("patches/faster_menu_dpad.txt",outfile) if zeal_end == "Y": patches.patch_file("patches/zeal_end_boss.txt",outfile) if lost_worlds == "Y": bigpatches.write_patch("patches/lost.ips",outfile) if lost_worlds == "Y": pass elif quick_pendant == "Y": patches.patch_file("patches/fast_charge_pendant.txt",outfile) print("Randomizing treasures...") treasures.randomize_treasures(outfile,difficulty) hardcoded_items.randomize_hardcoded_items(outfile) print("Randomizing enemy loot...") enemystuff.randomize_enemy_stuff(outfile,difficulty) print("Randomizing shops...") shops.randomize_shops(outfile) print("Randomizing character locations...") char_locs = char_slots.randomize_char_positions(outfile,locked_chars,lost_worlds) print("Now placing key items...") if lost_worlds == "Y": keyitemlist = keyitems.randomize_lost_worlds_keys(char_locs,outfile) else: keyitemlist = keyitems.randomize_keys(char_locs,outfile,locked_chars) if difficulty == "hard": bigpatches.write_patch("patches/hard.ips",outfile) if boss_scaler == "Y": print("Rescaling bosses based on key items..") boss_scale.scale_bosses(char_locs,keyitemlist,locked_chars,outfile) if tech_list == "Y": tech_order.take_pointer(outfile) # Tyrano Castle chest hack f = open(outfile,"r+b") f.seek(0x35F6D5) f.write(st.pack("B",1)) f.close() #Mystic Mtn event fix in Lost Worlds if lost_worlds == "Y": f = open(outfile,"r+b") bigpatches.write_patch("patches/mysticmtnfix.ips",outfile) #Bangor Dome event fix if character locks are on if locked_chars == "Y": bigpatches.write_patch("patches/bangorfix.ips",outfile) f.close() print("Randomization completed successfully.")
def generate_rom(): global flags global sourcefile global outputfolder global difficulty global glitch_fixes global fast_move global sense_dpad global lost_worlds global boss_rando global boss_scaler global zeal_end global quick_pendant global locked_chars global tech_list global seed global unlocked_magic global quiet_mode global chronosanity global tab_treasures global shop_prices # isolate the ROM file name inputPath = pathlib.Path(sourcefile) outfile = inputPath.name # Create the output file name outfile = outfile.split(".") outfile = str(outfile[0]) if flags == "": outfile = "%s.%s.sfc" % (outfile, seed) else: outfile = "%s.%s.%s.sfc" % (outfile, flags, seed) # Append the output file name to the selected directory # If there is no selected directory, use the input path if outputfolder == None or outputfolder == "": outfile = str(inputPath.parent.joinpath(outfile)) else: outfile = str(pathlib.Path(outputfolder).joinpath(outfile)) size = stat(sourcefile).st_size if size % 0x400 == 0: copyfile(sourcefile, outfile) elif size % 0x200 == 0: print("SNES header detected. Removing header from output file.") f = open(sourcefile, 'r+b') data = f.read() f.close() data = data[0x200:] open(outfile, 'w+').close() f = open(outfile, 'r+b') f.write(data) f.close() print("Applying patch. This might take a while.") bigpatches.write_patch_alt("patch.ips", outfile) patches.patch_file("patches/patch_codebase.txt", outfile) if glitch_fixes == "Y": patches.patch_file("patches/save_anywhere_patch.txt", outfile) patches.patch_file("patches/unequip_patch.txt", outfile) patches.patch_file("patches/fadeout_patch.txt", outfile) patches.patch_file("patches/hp_overflow_patch.txt", outfile) if fast_move == "Y": patches.patch_file("patches/fast_overworld_walk_patch.txt", outfile) patches.patch_file("patches/faster_epoch_patch.txt", outfile) if sense_dpad == "Y": patches.patch_file("patches/faster_menu_dpad.txt", outfile) if zeal_end == "Y": patches.patch_file("patches/zeal_end_boss.txt", outfile) if lost_worlds == "Y": bigpatches.write_patch_alt("patches/lost.ips", outfile) if lost_worlds == "Y": pass elif quick_pendant == "Y": patches.patch_file("patches/fast_charge_pendant.txt", outfile) if unlocked_magic == "Y": fastmagic.set_fast_magic_file(outfile) # bigpatches.write_patch_alt("patches/fastmagic.ips",outfile) if difficulty == "hard": bigpatches.write_patch_alt("patches/hard.ips", outfile) tabwriter.rewrite_tabs( outfile ) #Psuedoarc's code to rewrite Power and Magic tabs and make them more impactful print("Randomizing treasures...") treasures.randomize_treasures(outfile, difficulty, tab_treasures) hardcoded_items.randomize_hardcoded_items(outfile, tab_treasures) print("Randomizing enemy loot...") enemystuff.randomize_enemy_stuff(outfile, difficulty) print("Randomizing shops...") shops.randomize_shops(outfile) shops.modify_shop_prices(outfile, shop_prices) print("Randomizing character locations...") char_locs = char_slots.randomize_char_positions(outfile, locked_chars, lost_worlds) print("Now placing key items...") if chronosanity == "Y": chronosanity_logic.writeKeyItems(outfile, char_locs, (locked_chars == "Y"), (quick_pendant == "Y"), lost_worlds == "Y") elif lost_worlds == "Y": keyitemlist = keyitems.randomize_lost_worlds_keys(char_locs, outfile) else: keyitemlist = keyitems.randomize_keys(char_locs, outfile, locked_chars) if boss_scaler == "Y" and chronosanity != "Y": print("Rescaling bosses based on key items..") boss_scale.scale_bosses(char_locs, keyitemlist, locked_chars, outfile) #print("Boss rando: " + boss_rando) if boss_rando == "Y": boss_shuffler.randomize_bosses(outfile, difficulty) if tech_list == "Fully Random": tech_order.take_pointer(outfile) elif tech_list == "Balanced Random": tech_order.take_pointer_balanced(outfile) if quiet_mode == "Y": bigpatches.write_patch_alt("patches/nomusic.ips", outfile) # Tyrano Castle chest hack f = open(outfile, "r+b") f.seek(0x35F6D5) f.write(st.pack("B", 1)) f.close() #Mystic Mtn event fix in Lost Worlds if lost_worlds == "Y": f = open(outfile, "r+b") bigpatches.write_patch_alt("patches/mysticmtnfix.ips", outfile) bigpatches.write_patch_alt("patches/losteot.ips", outfile) #Bangor Dome event fix if character locks are on if locked_chars == "Y": bigpatches.write_patch_alt("patches/bangorfix.ips", outfile) f.close() print("Randomization completed successfully.")