Skip to content

Commit 7561114

Browse files
committed
Bug Fix when loading item ids with buffers in sub inventories
Closes #73 When loading items in subinventories their ID is extracted as a string. But in some edge cases for some strings (see capital C) the editor loads this wrongly because the DC4 character is in the string. For those special strings it backups the original binary string buffer it loaded. But now we tried to save an object containing that buffer as a string, which failed. We now check if the item ID is contained within such a buffer.
1 parent e9d6649 commit 7561114

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

main.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,12 @@ def get_inventory(inv):
786786
for _ in inv:
787787
item = dict()
788788
item["id"] = inv[i]["v"]["id"]["v"]
789+
790+
# The item ID can also be not a string but an object when during loading a error was encountered and it was
791+
# "fixed" and the original buffer saved, then the id is of course the item name which was fixed up
792+
if isinstance(item["id"], dict):
793+
item["id"] = item["id"]["string"]
794+
789795
item["durability"] = inv[i]["v"]["_params"]["v"]["_durability"]["v"]
790796
item["amount"] = inv[i]["v"]["value"]["v"]
791797
item["position"] = i
@@ -829,7 +835,10 @@ def edit_inventory(inventory, new_items, shash):
829835
temp_item = deepcopy(fallback_item)
830836

831837
# For the case the id is not in the serialized strings we just reapply it
832-
temp_item["v"]["id"] = modify_value_type(shash, temp_item["v"]["id"], item["id"])
838+
# We do some extra checks, hopefully not breaking an item id which would need a custom buffer due to the
839+
# D control character which capital C seems to contain in the item ids
840+
if "C" not in item["id"] or len(item["id"]) < 30 and item["id"] not in savefiles[shash]["serializer"]:
841+
temp_item["v"]["id"] = modify_value_type(shash, temp_item["v"]["id"], item["id"])
833842

834843
# Set additional parameters which might have been changed like the amount of the item
835844
temp_item["v"]["_params"]["v"]["_durability"] = modify_value_type(shash, temp_item["v"]["_params"]["v"]["_durability"], item["durability"])

0 commit comments

Comments
 (0)