aboutsummaryrefslogtreecommitdiff
path: root/srb.py
blob: ed96c4b0d8d0e3727ee62191589de4ed91ec27ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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