def make_stash(path, header, ver, gold, new_pages, ignored_pages): # Rewrite the stash file using the new (and ignored) stash pages with open(path, "wb") as f: # First write header and version f.write(header) f.write(ver) # If the stash is shared ("SSS\0") and ver 2, write the shared gold if header == b'SSS\x00' and ver == b'02': f.write(gold) # If the stash is personal, write 4 junk bytes. if header == b'CSTM': f.write(b'\x00\x00\x00\x00') # Write number of pages. It is possible to write these directly but easier to utilize the existing write_bits # method by feeding it some 4-byte string and having it rewrite it, since it already handles the endian issues f.write( write_bits(b'\x00\x00\x00\x00', 0, 32, len(ignored_pages) + len(new_pages))) # Write each ignored page back into the stash, unmodified from its original form for page in ignored_pages: f.write(page) # For the new pages, first write the header and flags, then the number of items, # and then each individual item. for page in new_pages: if header == b'SSS\x00': # For shared stashes, turn on the shared stash page flag f.write(b'ST\x01\x00\x00\x00\x00JM') if header == b'CSTM': # For personal stashes, keep all flags turned off f.write(b'ST\x00\x00\x00\x00\x00JM') # IF USING OLDER VERSIONS OF PLUGY, COMMENT OR DELETE THE 4 LINES ABOVE AND UNCOMMENT THE LINE BELOW # f.write(b'ST\x00JM') f.write(write_bits(b'\x00\x00', 0, 16, page.num_items())) for item in page.items: f.write(item.data)
def set_code(self, new_code): # Get new 3-letter item code and replace the old one for i in range(3): self.data = write_bits(self.data, 76 + i * 8, 8, ord(new_code[i])) self.data = write_bits(self.data, 100, 8, ord(' ')) self.code = new_code
def set_position(self, x, y): # Modify item data and write new stash position self.data = write_bits(self.data, 65, 4, x) self.data = write_bits(self.data, 69, 4, y)