From f02a5c56c1dc5baf89ead3026642a1e29114d64f Mon Sep 17 00:00:00 2001 From: omicron Date: Mon, 23 Oct 2023 05:02:25 +0200 Subject: [PATCH] Add simple script to edit item stat property values --- contrib/createitem.py | 64 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 contrib/createitem.py diff --git a/contrib/createitem.py b/contrib/createitem.py new file mode 100644 index 0000000..bf521b5 --- /dev/null +++ b/contrib/createitem.py @@ -0,0 +1,64 @@ +from bitarray import bitarray +from bitarray.util import int2ba, hex2ba +from textwrap import wrap +from struct import pack +import os +import sys + + +def make_stat(id, len, value): + id_bits = int2ba(id, length=9, endian="little") + value_bits = int2ba(value, length=len, endian="little") + return id_bits + value_bits + + +def make_stash(item_list: list[bytes]) -> bytes: + count = len(item_list) + items = b"".join(item_list) + return ( + bytes.fromhex("55aa55aa010000006300000000000000") + + pack("I", len(items) + 68) + + bytes.fromhex( + "0000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000004a4d" + ) + + pack("H", count) + + items + + bytes.fromhex( + "55aa55aa01000000630000000000000044000000000000" + "0000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000004a4d000055" + "aa55aa0100000063000000000000004400000000000000" + "0000000000000000000000000000000000000000000000" + "00000000000000000000000000000000004a4d0000" + ) + ) + + +def make_item() -> bytes: + bits = bitarray(endian="little") + bits.frombytes( + bytes.fromhex( + "10008000050014df170e5b7eca14c6ee66af344848981946c07101828715d15a3c1be3f90f" + ) + ) + # 9% cold ress + # stat = make_stat(43, 9, 200 + 9) + # print(stat) + # print(bits.find(stat)) + bits[231 : 231 + 18] = ( + make_stat(0, 8, 32 + 16) + make_stat(1, 7, 32 + 16) + make_stat(2, 7, 32 + 16) + ) + return bits.tobytes() + + +createpath = os.getenv("CREATEITEM_PATH") +if not createpath: + print( + "set the environment variable CREATEITEM_PATH to the stash file you want to overwrite" + ) + print("THIS WILL PERMANENTLY DESTROY ALL ITEMS IN THAT FILE") + sys.exit(1) + +with open(createpath, "wb") as f: + f.write(make_stash([make_item()]))