Skip to content

Commit

Permalink
Update l2db.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Lampe2020 committed Feb 26, 2023
1 parent 2370388 commit 0ddc62c
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions l2db.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,9 @@ def eval_db(self, database):
match self.metadata['DB_INDEX_TYPE']:
case dbindextype if dbindextype in (1, 2):
self.db = {
keyname: body[self.valtable[keyname][0]:self.valtable[keyname][0] + self.valtable[keyname][1]]
keyname: body[self.valtable[keyname][0]:self.valtable[keyname][1]]
for keyname in self.valtable}

case _:
if self.strict:
raise L2DBError(f"DB_INDEX_TYPE of {self.metadata['DB_INDEX_TYPE']} is not supported, \
Expand Down Expand Up @@ -284,7 +285,7 @@ def to_bytes(obj):
return helpers['bstr_from_str'](repr(obj)) if self.metadata['RAW_VALUES'] \
else b'str\x00' + helpers['bstr_from_str'](repr(obj)) # ...just represent it as a string

# Valtable+Body #FIXME: somewhere in this loop is an unwanted write to the database which destroys it more and more with each iteration...
# Valtable+Body
for key in self.db:
# Note that non-string keys will be stored as string keys!
match self.metadata['DB_INDEX_TYPE']:
Expand All @@ -293,15 +294,13 @@ def to_bytes(obj):
valtable += (helpers['bstr_from_int']( len(body), unsigned=True) \
+ helpers['bstr_from_int'](len(body_segment) + len(body), unsigned=True) \
+ helpers['bstr_from_str'](str(key)) + b'\x00')
# print(f'DB_INDEX_TYPE: 1, body len: {len(body)}, body_segment len: {len(body_segment)}, valtable: {valtable}, key: {key}, self.db[key]: {repr(self.db[key])}, body_segment: {body_segment}') #debug
case 2:
valtable += (helpers['bstr_from_long'](len(body), unsigned=True)
+ helpers['bstr_from_str'] (str(key)) + b'\x00')
body_segment = to_bytes(self.db[key])
# print(f'DB_INDEX_TYPE: 2, body len: {len(body)}, body_segment len: {len(body_segment)}, valtable: {valtable}, key: {key}, self.db[key]: {repr(self.db[key])}, body_segment: {body_segment}') #debug
body += body_segment
print(self.db) # debug
self.update_metadata('VALTABLE_LEN', len(valtable)) # This line seems to cause the above writes, several times inthe loop even though it's outside...
self.update_metadata('VALTABLE_LEN', len(valtable))

# Metadata
metadata = list(self.magic) + [0 for x in range(64 - len(self.magic))]
Expand Down

0 comments on commit 0ddc62c

Please sign in to comment.