From 18dc360893f5b4b8842630008c072e993bd25135 Mon Sep 17 00:00:00 2001 From: "B. Stack" Date: Mon, 18 Mar 2024 21:41:49 -0400 Subject: add get/add/remove purchased planes --- srb.py | 25 +++++++++++++++++---- srb_lib.py | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 85 insertions(+), 16 deletions(-) diff --git a/srb.py b/srb.py index f97e01b..81c8b5f 100755 --- a/srb.py +++ b/srb.py @@ -9,8 +9,8 @@ # delsum from github # bgconf.py -# WORKHERE: right now, this only just corrects any file. in the future, offer options like --take-plane all or --give-plane marcie -# or --give-plane marcie or --set-rank-level 1,general --set-rank-level 1,none --set-rank-level all,general +# WORKHERE: +# or --set-rank-level 1,general --set-rank-level 1,none --set-rank-level all,general # or --give-balloons-level 10 --take-balloons-level 11 # or --reset-level 5 (which zeros out all info about completion of that level) @@ -39,9 +39,12 @@ parser.add_argument("--get-weapon",action="store_true",help="Print currently equ #choices=[i for i in srb_lib.WEAPONS if i != "undefined"]+list(range(0,16)) #parser.add_argument("--set-weapon",choices=[i for i in srb_lib.WEAPONS if i != "undefined"],help="Print currently equipped weapon for profile.") parser.add_argument("--set-weapon",help="Set currently equipped weapon for profile.") -parser.add_argument("--get-purchased-weapons",action="store_true",help="Print currently purchased weapon for profile.") +parser.add_argument("--get-purchased-weapons",action="store_true",help="Print currently purchased weapons for profile.") parser.add_argument("--add-purchased-weapons",action="append",help="For profile, add these purchased weapons. Can be used multiple times.") parser.add_argument("--remove-purchased-weapons",action="append",help="For profile, remove (un-buy) these purchased weapons. Can be used multiple times.") +parser.add_argument("--get-purchased-planes",action="store_true",help="Print currently purchased planes for profile.") +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("--get-levelset",help="Print status for this levelset for profile.") parser.add_argument("--get-name",action="store_true",help="Print name for profile.") @@ -73,7 +76,7 @@ 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): +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): ferror("Warning: Cannot perform most actions without --profile. Not all tasks may run.") else: if args.get_money: @@ -165,6 +168,20 @@ else: print(f"Failed to set gun to {args.set_gun} because {message}") else: srb_lib.write_file(args.file,0,data) + if args.get_purchased_planes: + print(f"Profile {profile_id} has planes {srb_lib.get_purchased_planes(args.file,profile_id)}") + if args.add_purchased_planes: + data, message = srb_lib.set_purchased_planes(args.file,profile_id,"add",args.add_purchased_planes) + if (type(data) == int and data == -1) or message != "": + ferror(f"Failed to add purchased planes {args.add_purchased_planes} because {message}") + else: + srb_lib.write_file(args.file,0,data) + if args.remove_purchased_planes: + data, message = srb_lib.set_purchased_planes(args.file,profile_id,"remove",args.remove_purchased_planes) + if (type(data) == int and data == -1) or message != "": + ferror(f"Failed to add purchased planes {args.remove_purchased_planes} because {message}") + else: + srb_lib.write_file(args.file,0,data) if args.checksum: f = args.file diff --git a/srb_lib.py b/srb_lib.py index e8adab4..253a3be 100644 --- a/srb_lib.py +++ b/srb_lib.py @@ -20,7 +20,7 @@ # Dependencies: import sys, struct -srb_lib_version = "20240313a" +srb_lib_version = "20240318a" # Table of byte positions of values in the savegame file, minus the first four bytes which are the checksum. Due to zero-indexing of python lists, but for ease of usage, we will always put a zero as the value of index 0. That is, profile 1 will use index 1 of the list. # "Z