aboutsummaryrefslogtreecommitdiff
path: root/srb.py
diff options
context:
space:
mode:
authorB. Stack <bgstack15@gmail.com>2024-03-09 19:38:11 -0500
committerB. Stack <bgstack15@gmail.com>2024-03-09 19:38:11 -0500
commit6ead0ee4d37cb64ab36cb1727d3edf90d11adf64 (patch)
tree3a27c1bd88c6b54b12a9d986cd5b7d48e6dad866 /srb.py
downloadsrb_lib-6ead0ee4d37cb64ab36cb1727d3edf90d11adf64.tar.gz
srb_lib-6ead0ee4d37cb64ab36cb1727d3edf90d11adf64.tar.bz2
srb_lib-6ead0ee4d37cb64ab36cb1727d3edf90d11adf64.zip
initial commit
Diffstat (limited to 'srb.py')
-rwxr-xr-xsrb.py85
1 files changed, 85 insertions, 0 deletions
diff --git a/srb.py b/srb.py
new file mode 100755
index 0000000..ed96c4b
--- /dev/null
+++ b/srb.py
@@ -0,0 +1,85 @@
+#!/usr/bin/env python3
+# Startdate: 2024-03-08-6 15:28
+# File: srb_lib.py
+# Purpose: frontend for srb_lib
+# History:
+# Usage:
+# Reference:
+# blog posts 2024-03
+# delsum from github
+# bgconf.py
+
+# WORKHERE: right now, this only just corrects any file. in the future, offer options like --profile 1 --set-money 3045 --give-plane all or --give-plane marcie
+# or --take-plan marcie or --set-rank-level 1,general --set-rank-level 1,none --set-rank-level all,general
+# or --give-weapon pumpkin --take-weapon bees
+# or --give-balloons-level 10 --take-balloons-level 11
+# make chart of level numbers, which ones have balloons
+# or --reset-level 5 (which zeros out all info about completion of that level)
+# --set-plane-health 1 (through 4)
+# --set-plane-weapon 1 (through 4)
+# --set-plane-stunt 1 (through 4)
+# --set-profile-name "asdbdf"
+
+import srb_lib, argparse, sys
+from srb_lib import ferror, debuglev
+
+parser = argparse.ArgumentParser(description="Cli tool for manipulating savegame files for srb.exe")
+parser.add_argument("-V","--version",action="version",version="%(prog)s " + srb_lib.srb_lib_version)
+parser.add_argument("-d","--debug",nargs='?',default=0,type=int,choices=range(0,11),help="Set debug level")
+parser.add_argument("--profile",type=int,choices=range(1,4),help="Profile in user menu.")
+parser.add_argument("--get-money",action="store_true",help="Print current money for profile.")
+parser.add_argument("--set-money",type=int,help="Set money for profile.")
+parser.add_argument("--get-weapon",action="store_true",help="Print currently equipped weapon for profile.")
+# choices seems to be too strict here for the numbers. We can live with just the
+#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="Print currently equipped weapon for profile.")
+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()
+debuglevel = 0
+if args.debug:
+ debuglevel = args.debug
+
+if debuglev(1,debuglevel):
+ ferror("debug level", debuglevel)
+if debuglev(8,debuglevel):
+ ferror(args)
+
+# common parameters
+profile_id = args.profile
+
+print(f"profile_id={profile_id}")
+
+if not profile_id and (args.get_money or args.set_money or args.get_weapon or args.set_weapon):
+ ferror("Warning: Cannot perform most actions without --profile. Not all tasks may run.")
+else:
+ if args.get_money:
+ money = srb_lib.get_money(args.file, profile_id)
+ print(f"Profile {profile_id} has {money} money.")
+ if args.set_money:
+ if args.set_money > 0xFFFF:
+ ferror(f"Warning: Do not set money higher than 65535. While it can technically work, there's no need for that in-game anyways. Continuing...")
+ else:
+ data = srb_lib.set_money(args.file, profile_id, args.set_money)
+ srb_lib.write_file(args.file,0,data)
+ if args.get_weapon:
+ print(f"Profile {profile_id} has weapon {srb_lib.get_weapon(args.file, profile_id)}")
+ if args.set_weapon:
+ try:
+ args.set_weapon = int(args.set_weapon)
+ except:
+ pass
+ data = srb_lib.set_weapon(args.file, profile_id, args.set_weapon)
+ if type(data) == int and data == -1:
+ # error is printed in the function
+ pass
+ else:
+ srb_lib.write_file(args.file,0,data)
+
+if args.checksum:
+ f = args.file
+ #for f in args.file:
+ if debuglev(1,debuglevel):
+ ferror(f"Fixing checksum for file {f}")
+ srb_lib.correct_file(f,debuglevel)
bgstack15