def find_player_changeform(cfcount: int, formidarray: List[int], i: int, data: bytes) -> Tuple[int, Tuple[bytes, int, int]]: """ Go through all ChangeForms until the player is found and return it. The format is: formID RefID changeFlags uint32 type uint8 type of form version uint8 length1 int length of the data length2 int 0 or length of uncompressed data data uint8[length1] """ for n in range(cfcount): refid = data[i:i + 3] formid = parse_refid(refid, formidarray) i += 3 flags = uint32(data[i:i + 4]) i += 4 cftype = uint8(data[i:i + 1]) i += 1 # Top 2 bits are the size of data lengths (ln1 and ln2) lengthsize = [8, 16, 32][cftype >> 6] # Lower 6 bits are the type of form formtype = cftype & 63 # The Skyrim version (currently unused) version = uint8(data[i:i + 1]) #assert version in [57, 64, 73, 74] i += 1 # The actual length ln1 = uint(lengthsize, data[i:i + 4]) i += lengthsize // 8 # Compressed length or 0 if uncompressed ln2 = uint(lengthsize, data[i:i + 4]) i += lengthsize // 8 + ln1 if formid == 7 and formtype == 9: return 0, (data[i - ln1:i], ln2, flags)
def find_player_changeform(cfcount: int, formidarray: List[int], i: int, data: bytes) -> Tuple[int, Tuple[bytes, int, int]]: """ Go through all ChangeForms until the player is found and return it. The format is: formID RefID changeFlags uint32 type uint8 type of form version uint8 length1 int length of the data length2 int 0 or length of uncompressed data data uint8[length1] """ for n in range(cfcount): refid = data[i:i+3] formid = parse_refid(refid, formidarray) i += 3 flags = uint32(data[i:i+4]) i += 4 cftype = uint8(data[i:i+1]) i += 1 # Top 2 bits are the size of data lengths (ln1 and ln2) lengthsize = [8, 16, 32][cftype >> 6] # Lower 6 bits are the type of form formtype = cftype & 63 # The Skyrim version (currently unused) version = uint8(data[i:i+1]) #assert version in [57, 64, 73, 74] i += 1 # The actual length ln1 = uint(lengthsize, data[i:i+4]) i += lengthsize//8 # Compressed length or 0 if uncompressed ln2 = uint(lengthsize, data[i:i+4]) i += lengthsize//8 + ln1 if formid == 7 and formtype == 9: return 0, (data[i-ln1:i], ln2, flags)
def parse_uint(bits: int, i: int, data: bytes) -> Tuple[int, int]: return bits // 8, uint(bits, data[i:i + 4])
def parse_uint(bits: int, i: int, data: bytes) -> Tuple[int, int]: return bits//8, uint(bits, data[i:i+4])