Example #1
0
def testpatch():
    # open the skyloft cave file
    with open(EXTRACT_ROOT_PATH + '/DATA/files/Stage/D000/D000_stg_l0.arc.LZ',
              'rb') as f:
        # extract in memory
        data = nlzss11.decompress(f.read())
        data = BytesIO(data)
        data = U8File.parse_u8(data)

        # add hookshot and gust bellows
        with open('oarc/GetHookShot.arc', 'rb') as h:
            data.add_file_data('oarc/GetHookShot.arc', h.read())

        with open('oarc/GetVacuum.arc', 'rb') as h:
            data.add_file_data('oarc/GetVacuum.arc', h.read())

        # open room
        # room=parse_bzs(data.get_data('rarc/D000_r00.arc:dat/room.bzs'))
        # get objects
        # objects=room.children['LAY '].layers[0].children['OBJS'].objects
        # find chest with id 68 and replace the content with hookshot
        # for obj in objects:
        #     if obj['name']==b'TBox\x00\x00\x00\x00':
        #         if (obj['talk_behaviour']&0xF700)>>9 == 64:
        #             obj['talk_behaviour']==(obj['talk_behaviour']&0xF700)+0x14
        #             print('patched hookshot')
        # for obj in objects:
        #     if obj['name']==b'TBox\x00\x00\x00\x00':
        #         if (obj['talk_behaviour']&0xF700)>>9 == 67:
        #             obj['talk_behaviour']==(obj['talk_behaviour']&0xF700)+0x31
        #             print('patched gust bellows')

        # write room back
        # data.update_file('rarc/D000_r00.arc:dat/room.bzs',build_bzs(room))
        # write stage to memory
        # with open('D000_stg_l0.arc', 'wb') as o:
        #     data.writeto(o)
        return data