diff options
author | B. Stack <bgstack15@gmail.com> | 2024-03-19 18:27:40 -0400 |
---|---|---|
committer | B. Stack <bgstack15@gmail.com> | 2024-03-19 18:27:40 -0400 |
commit | 1d8157e42dc12ce3b3f5fe5bd7e1fdea2de483ac (patch) | |
tree | f24ac609cd2463c5541966a3eaa0a776c774c846 /srb.py | |
parent | set levelset available levels (diff) | |
download | srb_lib-1d8157e42dc12ce3b3f5fe5bd7e1fdea2de483ac.tar.gz srb_lib-1d8157e42dc12ce3b3f5fe5bd7e1fdea2de483ac.tar.bz2 srb_lib-1d8157e42dc12ce3b3f5fe5bd7e1fdea2de483ac.zip |
add set-level-letters, un/lock everything, un/buy everything
Diffstat (limited to 'srb.py')
-rwxr-xr-x | srb.py | 167 |
1 files changed, 158 insertions, 9 deletions
@@ -4,15 +4,12 @@ # Purpose: frontend for srb_lib # History: # Usage: +# tl;dr: ./srb.py --profile 1 --unlock-everything --buy-everything "Profile 1.sav" # Reference: # blog posts 2024-03 # delsum from github # bgconf.py - -# WORKHERE: -# or --reset-level 5 (which zeros out all info about completion of that level) -# --set-level-letters 0,none 0,all -# --set-level 0,done 5,new # sets balloons 10, status general, letters all +# WORKHERE: still some confusion around the --unlock-everything --lock-everything and the levelset available levels. import srb_lib, argparse, sys from srb_lib import ferror, debuglev @@ -46,8 +43,10 @@ parser.add_argument("--get-purchased-planes",action="store_true",help="Print cur parser.add_argument("--add-purchased-planes",action="append",help="For profile, add these purchased planes. Can be used multiple times.") parser.add_argument("--remove-purchased-planes",action="append",help="For profile, remove (un-buy) these purchased planes. Can be used multiple times.") parser.add_argument("--get-level",help="Print status for this level for profile.") +parser.add_argument("--set-level",action="append",help="Set completion status, balloons, letters for this level for profile. Example value to pass: 0,all 15,none") parser.add_argument("--set-level-status",action="append",help="Set completion status for this level for profile. Example value to pass: \"0,general\"") parser.add_argument("--set-level-balloons",action="append",help="Set balloon status for this level for profile. Example value to pass: \"0,all\" or \"0,none\"") +parser.add_argument("--set-level-letters",action="append",help="Set collected letters for level for profile. Examples: 0,all 15,none") parser.add_argument("--get-levelset",help="Print status for this levelset for profile.") parser.add_argument("--set-levelset-available-levels",action="append",help="Set number of available levels in this levelset for profile.") parser.add_argument("--get-name",action="store_true",help="Print name for profile.") @@ -60,7 +59,11 @@ parser.add_argument("--set-health",type=int,choices=range(1,5),help="Set stat he parser.add_argument("--get-stunt",action="store_true",help="Print stat stunt for profile.") parser.add_argument("--set-stunt",type=int,choices=range(1,5),help="Set stat stunt for profile.") parser.add_argument("--get-gun",action="store_true",help="Print stat gun for profile.") -parser.add_argument("--set-gun",type=int,choices=range(1,6),help="Set stat gun for profile.") +parser.add_argument("--set-gun",type=int,choices=range(1,6),help="Set stat gun for profile. 5 is octo-gun which normally unlocks at 100% completion of the game.") +parser.add_argument("--lock-everything",action="store_true",help="Set all levels to completed with rank general, all letters, and all balloons.") +parser.add_argument("--unlock-everything",action="store_true",help="Set all levels to not completed. Take all letters and balloons.") +parser.add_argument("--buy-everything",action="store_true",help="Give all purchasable items: planes, weapons, plane stats.") +parser.add_argument("--unbuy-everything",action="store_true",help="Remove all purchasable items: planes, weapons, plane stats.") parser.add_argument("--checksum",action=argparse.BooleanOptionalAction,default=True,help="Correct checksum. Default is to do this. It happens at the end of everything else.") parser.add_argument("file",default="Profile 1.sav") args = parser.parse_args() @@ -78,8 +81,8 @@ profile_id = args.profile #print(f"profile_id={profile_id}") -# WORKHERE: new actions that need --profile must be added here. -if not profile_id and (args.get_money or args.set_money or args.get_weapon or args.set_weapon or args.get_level or args.get_name or args.set_name or args.get_profile_in_use or args.get_purchased_weapons or args.get_tutorial_completed or args.add_purchased_weapons or args.remove_purchased_weapons or args.get_health or args.get_stunt or args.get_gun or args.set_health or args.set_stunt or args.set_gun or args.get_levelset or args.get_purchased_planes or args.add_purchased_planes or args.remove_purchased_planes or args.set_level_status or args.set_level_balloons or args.set_levelset_available_levels): +# New actions that need --profile must be added here. +if not profile_id and (args.get_money or args.set_money or args.get_weapon or args.set_weapon or args.get_level or args.get_name or args.set_name or args.get_profile_in_use or args.get_purchased_weapons or args.get_tutorial_completed or args.add_purchased_weapons or args.remove_purchased_weapons or args.get_health or args.get_stunt or args.get_gun or args.set_health or args.set_stunt or args.set_gun or args.get_levelset or args.get_purchased_planes or args.add_purchased_planes or args.remove_purchased_planes or args.set_level_status or args.set_level_balloons or args.set_levelset_available_levels or args.set_level_letters or args.unlock_everything or args.lock_everything or args.buy_everything or args.unbuy_everything or args.set_level): ferror("Warning: Cannot perform most actions without --profile. Not all tasks may run.") else: if args.get_money: @@ -225,13 +228,159 @@ else: try: levelset_num, count = l.split(",") except: - ferror(f"Warning! Skipping un-parseable level completion spec {l}. Please use \"0,general\" format.") + ferror(f"Warning! Skipping un-parseable levelset available spec {l}. Please use \"0,all\" format.") if levelset_num != -1: data, message = srb_lib.set_levelset_available_levels(args.file,profile_id,levelset_num,count) if (type(data) == int and data == -1) or message != "": ferror(f"Failed to set profile {profile_id} level {levelset_num} available levels to {count} because {message}") else: srb_lib.write_file(args.file,0,data) + if args.set_level_letters: + for l in args.set_level_letters: + level_num = -1 + try: + level_num, count = l.split(",") + except: + ferror(f"Warning! Skipping unparseable level letter spec {l}. Please use \"0,all\" format.") + if level_num != -1: + data, message = srb_lib.set_level_letters(args.file,profile_id,level_num, count) + if (type(data) == int and data == -1) or message != "": + ferror(f"Failed to set profile {profile_id} level {levelset_num} available levels to {count} because {message}") + else: + #print(f"good?") + srb_lib.write_file(args.file,0,data) + if args.unlock_everything: + data = srb_lib._get_data_from_data_object(args.file) + # counting backwards helps the levelset available levels count. + for i in range(len(srb_lib.LEVELS)-1,0,-1): + data, new_status, message = srb_lib.set_level_status(data,profile_id,i,"general") + if message != "": + ferror(f"Failed on loop {i}, set_level_status, {message}") + break + data, message = srb_lib.set_level_balloons(data,profile_id,i,"all") + if message != "": + ferror(f"Failed on loop {i}, set_level_balloons, {message}") + break + data, message = srb_lib.set_level_letters(data,profile_id,i,"all") + if message != "": + ferror(f"Failed on loop {i}, set_level_letters, {message}") + break + for i in range(len(srb_lib.LEVELSETS)-1,0,-1): + data, message = srb_lib.set_levelset_available_levels(data,profile_id,i,"all") + if message != "": + ferror(f"Failed on levelset loop {i}, {message}") + break + if (type(data) == int and data == -1) or message != "": + ferror(f"Failed to unlock everything as indicated above.") + else: + srb_lib.write_file(args.file,0,data) + if args.lock_everything: + data = srb_lib._get_data_from_data_object(args.file) + # counting backwards helps the levelset available levels count. + for i in range(len(srb_lib.LEVELS)-1,0,-1): + data, new_status, message = srb_lib.set_level_status(data,profile_id,i,"none") + if message != "": + ferror(f"Failed on loop {i}, set_level_status, {message}") + break + data, message = srb_lib.set_level_balloons(data,profile_id,i,"none") + if message != "": + ferror(f"Failed on loop {i}, set_level_balloons, {message}") + break + data, message = srb_lib.set_level_letters(data,profile_id,i,"none") + if message != "": + ferror(f"Failed on loop {i}, set_level_letters, {message}") + break + for i in range(len(srb_lib.LEVELSETS)-1,0,-1): + data, message = srb_lib.set_levelset_available_levels(data,profile_id,i,"none") + if message != "": + ferror(f"Failed on levelset loop {i}, {message}") + break + if (type(data) == int and data == -1) or message != "": + ferror(f"Failed to lock everything as indicated above.") + else: + srb_lib.write_file(args.file,0,data) + if args.buy_everything: + data, message = srb_lib.set_purchased_weapons(args.file,profile_id,"add",["all"]) + if (type(data) == int and data == -1) or message != "": + ferror(f"Failed to remove purchased weapons ['all'] because {message}") + else: + data, message = srb_lib.set_purchased_planes(data,profile_id,"add",["all"]) + if (type(data) == int and data == -1) or message != "": + ferror(f"Failed to add purchased planes ['all'] because {message}") + else: + data, message = srb_lib.set_plane_stat(data,profile_id,"health",4) + if data == -1 or message != "": + print(f"Failed to set health to 4 because {message}") + else: + data, message = srb_lib.set_plane_stat(data,profile_id,"stunt",4) + if data == -1 or message != "": + print(f"Failed to set stunt to 4 because {message}") + else: + data, message = srb_lib.set_plane_stat(data,profile_id,"gun",5) + if data == -1 or message != "": + print(f"Failed to set gun to 5 because {message}") + # srb_lib.write_file(args.file,0,data) + if (type(data) == int and data == -1) or message != "": + ferror(f"Failed to buy everything as indicated above.") + else: + srb_lib.write_file(args.file,0,data) + if args.unbuy_everything: + data, message = srb_lib.set_purchased_weapons(args.file,profile_id,"remove",["all"]) + if (type(data) == int and data == -1) or message != "": + ferror(f"Failed to remove purchased weapons ['all'] because {message}") + else: + data, message = srb_lib.set_purchased_planes(data,profile_id,"remove",["all"]) + if (type(data) == int and data == -1) or message != "": + ferror(f"Failed to remove purchased planes ['all'] because {message}") + else: + data, message = srb_lib.set_plane_stat(data,profile_id,"health",1) + if data == -1 or message != "": + print(f"Failed to set health to 1 because {message}") + else: + data, message = srb_lib.set_plane_stat(data,profile_id,"stunt",1) + if data == -1 or message != "": + print(f"Failed to set stunt to 1 because {message}") + else: + data, message = srb_lib.set_plane_stat(data,profile_id,"gun",1) + if data == -1 or message != "": + print(f"Failed to set gun to 1 because {message}") + # srb_lib.write_file(args.file,0,data) + if (type(data) == int and data == -1) or message != "": + ferror(f"Failed to unbuy everything as indicated above.") + else: + srb_lib.write_file(args.file,0,data) + if args.set_level: + for i in args.set_level: + level_num = -1 + status = "" + cont = True + try: + level_num, status = i.split(",") + except: + ferror(f"Warning! Unable to set level spec {i}. Use \"0,all\" or \"15,none\" syntax.") + cont = False + if status not in ["all","none"]: + ferror(f"Warning! Unable to set level {level_num} to {status}. Use all or none.") + cont = False + if level_num != -1: + data, new_status, message = srb_lib.set_level_status(args.file,profile_id,level_num,"general" if status == "all" else "none") + if message != "": + ferror(f"Failed on {i}, set_level_status, {message}") + cont = False + if cont: + data, message = srb_lib.set_level_balloons(data,profile_id,level_num,status) + if message != "": + ferror(f"Failed on {i}, set_level_balloons, {message}") + cont = False + if cont: + data, message = srb_lib.set_level_letters(data,profile_id,level_num,status) + if message != "": + ferror(f"Failed on {i}, set_level_letters, {message}") + cont = False + if (type(data) == int and data == -1) or message != "" or not cont: + ferror(f"Failed to set profile {profile_id} level {level_num} status to {completion} because {message}") + else: + srb_lib.write_file(args.file,0,data) if args.checksum: f = args.file |