Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/rrooij/sd3save_editor
Browse files Browse the repository at this point in the history
  • Loading branch information
rdrooij committed Apr 6, 2019
2 parents dba4d74 + b79e174 commit be0c26d
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion sd3save_editor/save.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,22 @@ def _encode(self, obj, context):
return zeroes


class LocationAdapter(Adapter):
"""Location data appears to be loaded as a 12bit integer by the game
This works around the absence of such a type in python core, it functions
by truncating 4 bits from the provided 16, and zeroes out the leading 4
bits on writing
"""
def _decode(self, obj, context):
int16 = int.from_bytes(obj, byteorder='little')
bit_str12 = bin(int16)[2:].zfill(16)[4:]
return int(bit_str12, 2)

def _encode(self, obj, context):
bit_str = '0000%s' % bin(obj)[2:].zfill(16)[4:]
return int(bit_str, 2).to_bytes(2, byteorder='little')


char_header = Struct(
"name"/CharacterNameAdapter(Bytes(12)),
"lvl"/Int8sl,
Expand Down Expand Up @@ -179,7 +195,7 @@ def _encode(self, obj, context):
"unclear4"/Bytes(530),
"item_storage"/Int8sl[102],
"unclear5"/Bytes(26),
"location"/Int16sl,
"location"/LocationAdapter(Bytes(2)),
"unclear6"/Bytes(46),
"item_ring"/Int8sl[10],
"unclear7"/Bytes(158)
Expand Down

0 comments on commit be0c26d

Please sign in to comment.