Accept unsigned values in signed fields when packing

Dumps made before the signed-read change store values like -1 as
4294967295. write_long now converts 2147483648..4294967295 to the
signed equivalent (same bytes), so existing community dumps still
pack. Verified: all 10332 files of an older dump repack identical.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
MagicBotandClaude Opus 5.5 committed 2026-10-16 13:09:05 -04:00
1 parent 50d8d76a21
commit 7bcbed08a8
2 files changed
+8 -7

No files matched your search

+5 -7
View File
@@ -25,13 +25,11 @@ The binary `.cache` format did not change. Every resource in
| Signed 32-bit fields | Values that were `4294967295` are now `-1`, `4294967286` is now `-10`, and so on | Accept negative integers |
| Grant attribute and power keys | First element of each pair is now a name string when the hash is known | Accept a string or an integer; convert names with `string_to_hash` |
Old JSON dumps are not fully compatible. `4294967295` and `-1` are the same
four bytes, but the packer now writes signed fields with `struct.pack('<i')`,
which rejects values above `2147483647` with `struct.error`. The sample dump has
such values (`rank_hirelings`, `rank_rank`, `attr_value`). Re-run
`unpack cobjects` to regenerate old dumps, or convert those values by
subtracting `4294967296`, before packing. Integer grant keys in old dumps still
pack unchanged.
Old JSON dumps still pack. `4294967295` and `-1` are the same four bytes, and
`ResStream.write_long` accepts either form: values from `2147483648` to
`4294967295` are converted to their signed equivalent before packing. Integer
grant keys in old dumps also pack unchanged. Re-running `unpack cobjects` is
only needed to see the new signed values and grant key names in the JSON.
## 1. Signed 32-bit fields
+3
View File
@@ -77,6 +77,9 @@ class ResStream:
self.buffer.write(data)
def write_long(self, value):
# Older dumps stored signed fields as unsigned; both forms are the same bytes.
if 0x7FFFFFFF < value <= 0xFFFFFFFF:
value -= 0x100000000
data = struct.pack('<i', value)
self.buffer.write(data)