Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- LICENCE: free, do whatever you want
- This script exports characters from Wizardry 8 save games into CHR files.
- OFFSETS:
- NAME, NICKNAME 9, 29
- For future use
- STRENGTH 233, 237
- INTELLIGENCE 253, 257
- PIETY 273, 277
- VITALITY 293, 297
- DEXTERITY 313, 317
- SPEED 333, 337
- SENSES 353, 357
- """
- from pathlib import Path
- from argparse import ArgumentParser
- # Constants: starting byte sequence of character and character data length
- HEADER = b'b\x18\x00\x00\x01\x00\x00\x00'
- CHRLEN = 6246
- def find_all(a_str, sub):
- """
- Function to find all occurrence of substring in string
- :param a_str: string to search in
- :param sub: substring to search for
- :return: found offsets
- """
- start = 0
- while True:
- start = a_str.find(sub, start)
- if start == -1:
- return
- yield start
- start += len(sub)
- def main(args):
- savebin = Path(args.save).read_bytes()
- party_offsets = list(find_all(savebin, HEADER))
- if len(party_offsets) == 0:
- print('No characters found!')
- for offset in party_offsets:
- chrbin = savebin[offset:offset+CHRLEN]
- name = ''
- index = 29
- nextchar = chrbin[index:index+1].hex()
- # print(chrbin[:28].hex(' '))
- while str(nextchar) != '00':
- name += chr(int(nextchar, 16))
- index += 2
- nextchar = chrbin[index:index+1].hex()
- print(f'Character: {name}')
- ascii = chrbin.hex(' ').split()
- ascii[8] = '00' # clear flag "character is in party"
- export_bin = bytearray.fromhex("".join(ascii))
- Path(f'{args.folder}/{name}_{args.suffix}.CHR').write_bytes(export_bin)
- print(f'Exported file: {args.folder}/{name}_{args.suffix}.CHR')
- if __name__ == '__main__':
- parser = ArgumentParser()
- parser.add_argument('--save', required=True, help="Path to Wizardry 8 SAV file")
- parser.add_argument('--suffix', default='exported', help="Suffix to add to exported CHR name")
- parser.add_argument('--folder', default='./', help="Folder to save characters")
- args = parser.parse_args()
- main(args)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement