def pack_test(): global DEBUG_MODE f = open('envpsp.dat', 'rb') b = Buffer(mmap(f.fileno(), 0, access=ACCESS_COPY)) oi = OrnamentInfo(f) l = 'A Siscaly knockout tournament has been organized nationwide in order to choose the strongest "Sister User". To Kirino, who really loves sister-related games, she has alot of interest in this tournament. On a side note, Siscalys official title is [Shin Imouto Taisen Siscalypse], a 3D Bishoujo versus game. And so, I probably cant refuse to participate...' pgf = PGFFont('../pypgf/fonts/sonyjpn.pgf') w = 360 * 64 h = (pgf.maxSizeV/64 * 3) + pgf.maxGlyphH + 10 old_size = len(oi.pack()) oi.entries[0].replace(pgf, l, w, h) print([page.decoded for page in oi.entries[0].pages], debug=True) new_oi = StringIO(oi.pack()) print(hexlify(oi.entries[0].pack()), debug=True) DEBUG_MODE = False new_oi = OrnamentInfo(new_oi, 0) new_size = len(new_oi.pack()) print(new_oi.entries[0].pages, debug=True) DEBUG_MODE = True print('Need %d bytes' % (new_size - old_size)) b.allocate_at(INFO_OFFSET, new_size - old_size) b.buf.seek(INFO_OFFSET) b.buf.write(new_oi.pack()) b.save('envpsp.dat') f.close()