From 1d0a6c692218703677cdcf8e6ceb98640ad36515 Mon Sep 17 00:00:00 2001 From: "B. Stack" Date: Sun, 10 Mar 2024 23:05:43 -0400 Subject: add get/set name --- srb_lib.py | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 3 deletions(-) (limited to 'srb_lib.py') diff --git a/srb_lib.py b/srb_lib.py index dc69614..1b13175 100644 --- a/srb_lib.py +++ b/srb_lib.py @@ -18,16 +18,19 @@ # winetricks vd=1024x768 # winetricks vd=off # Dependencies: -# python3-crcmod import sys, struct -srb_lib_version = "20240309a" +srb_lib_version = "20240310a" # 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. # money is 0x270 bytes after the "Z 8 or len(name_array) < 0: + return -1, f"Invalid length {len(name_array)} of name {new_name}." + x = 0 + # for some reason I cannot figure out '<8i' with a tuple or list of ints. So just do it manually. + for i in name_array: + struct.pack_into('<1i',data_bytearray,PROFILE_START_POSITION[profile_id]+POS_NAME+(4*x),i) + x = x + 1 + data = bytes(data_bytearray) + #print(f"debug: after setting name to {new_name}, we checked and got {get_name(data,profile_id)}") + return data, "" + +def get_profile_in_use(data_object,profile_id): + """ Print if the profile_id is in use. """ + data = _get_data_from_data_object(data_object) + # it always comes as a tuple + in_use = struct.unpack_from('<1?',data,PROFILE_START_POSITION[profile_id]+POS_PROFILE_IN_USE)[0] + #print(f"debug: in_use: {in_use}, type {type(in_use)}") + return in_use + def calculate_checksum(data): """ Return the 4-byte checksum used by the game for the provided data. """ # aka # CRC-32/BZIP2 -- cgit