diff options
author | B. Stack <bgstack15@gmail.com> | 2024-03-11 19:37:07 -0400 |
---|---|---|
committer | B. Stack <bgstack15@gmail.com> | 2024-03-11 19:37:07 -0400 |
commit | adf17836958d635ac70ace3146c9871c65c3dd99 (patch) | |
tree | 65e4a30f41ea1539f6f7882d02dae322e4e2bdf2 /srb_lib.py | |
parent | get/set purchased weapons (diff) | |
download | srb_lib-adf17836958d635ac70ace3146c9871c65c3dd99.tar.gz srb_lib-adf17836958d635ac70ace3146c9871c65c3dd99.tar.bz2 srb_lib-adf17836958d635ac70ace3146c9871c65c3dd99.zip |
add get/set plane stats
Diffstat (limited to 'srb_lib.py')
-rw-r--r-- | srb_lib.py | 38 |
1 files changed, 38 insertions, 0 deletions
@@ -26,6 +26,9 @@ srb_lib_version = "20240311a" # money is 0x270 bytes after the "Z<dddddddd" start. PROFILE_START_POSITION = [0, 0x10, 0x142C, 0x2848] POS_MONEY = 0x270 +POS_HEALTH = 0x274 # 0-3 is available levels +POS_STUNT = 0x280 # 0-3 is available levels +POS_GUN = 0x27C # 0-3 is available levels POS_EQUIPPED_WEAPON = 0x284 POS_PROFILE_IN_USE = 0x290 POS_NAME = 0x294 @@ -71,6 +74,7 @@ LEVELSETS = [ POS_LEVEL_START = 0x2D8 # each level position is POS_LEVEL_START + (4*level["pos_r"]) # the relative position is because each level set gets 7 (or 6 plus 1 blank) slots, but not all levelsets have 6 levels. +# WORKHERE 2024-03-11-2 19:29 porifle 3 replay mission 0, get the letter and maybe a few more balloons? LEVELS = [ {"id":0, "pos_r":0, "setid":0,"name":"Defend Island"}, {"id":1, "pos_r":1, "setid":0,"name":"Recover Plans"}, @@ -313,6 +317,7 @@ def get_level_status(data_object,profile_id,level): ferror(f"Unable to get level status for {level}.") print(f"Debug: got level_obj {level_obj} and message {message}") profile_level_status = data[PROFILE_START_POSITION[profile_id]+POS_LEVEL_START+(4*level_obj["pos_r"])] + print(f"Debug: got level status {profile_level_status:x} at pos 0x{PROFILE_START_POSITION[profile_id]+POS_LEVEL_START+(4*level_obj['pos_r'])}") # it comes back as an int, but does it look better as a hex? return hex(profile_level_status) @@ -398,6 +403,39 @@ def set_tutorial_completed(data_object,profile_id,completed): data = srb_pack('<?',data,PROFILE_START_POSITION[profile_id]+POS_TUTORIAL_COMPLETED,bool(completed)) return data, get_tutorial_completed(data,profile_id) +def get_plane_stat(data_object,profile_id,stat): + """ Get health/stunt/gun statistic for profile. """ + data = _get_data_from_data_object(data_object) + stat = stat.lower() + if stat not in ["health","stunt","gun"]: + return -1, f"Available plane stats are health,stunt,gun." + if "health" == stat: + thispos = POS_HEALTH + elif "stunt" == stat: + thispos = POS_STUNT + else: # gun + thispos = POS_GUN + output = struct.unpack_from('<1i',data,PROFILE_START_POSITION[profile_id]+thispos)[0]+1 + #print(f"debug: at offset {PROFILE_START_POSITION[profile_id]+thispos:x} got {output:1b}") + return output, "" + +def set_plane_stat(data_object,profile_id,stat,value): + """ Set health/stunt/gun statistic for profile. """ + data = _get_data_from_data_object(data_object) + stat = stat.lower() + if stat not in ["health","stunt","gun"]: + return -1, f"Available plane stats are health,stunt,gun." + if value not in range(1,6) or (value == 5 and stat != "gun"): + return -1, f"Invalid value {value} for stat." + if "health" == stat: + thispos = POS_HEALTH + elif "stunt" == stat: + thispos = POS_STUNT + else: # gun + thispos = POS_GUN + data = srb_pack('<1i',data,PROFILE_START_POSITION[profile_id]+thispos,value-1) + return data, "" + def set_purchased_weapons(data_object,profile_id,action,weapons_list): """ For the given profile, take action on weapons_list, where action is in ["add","remove"] from the player. """ data = _get_data_from_data_object(data_object) |