init offset = 9999

init python:
    config.after_load_callbacks.append(lambda: unlock_all())
    config.start_callbacks.append(lambda: unlock_all())

    def unlock_all():
        store = renpy.store
        
        for name, obj in store.__dict__.items():
            if name.startswith("_"):
                continue
            try:
                if hasattr(obj, 'scenes') and hasattr(obj, 'affection'):
                    obj.scenes = 10
                    obj.affection = 100
                    if hasattr(obj, 'choices'):
                        obj.choices = [c for c in obj.choices if "reject" not in str(c).lower()]
                        if "girlfriend" not in obj.choices:
                            obj.choices.append("girlfriend")
                    if hasattr(obj, 'peek_permission'):
                        obj.peek_permission = True
                    if hasattr(obj, 'peek_you'):
                        obj.peek_you = True
            except:
                pass
        
        for name in store.__dict__:
            if 'scene' in name.lower() and not name.startswith("_"):
                try:
                    val = getattr(store, name)
                    if isinstance(val, int):
                        setattr(store, name, 999)
                except:
                    pass
        
        if hasattr(store, 'pc'):
            pc = store.pc
            for stat in ['knowledge', 'lewdness', 'voyeurism', 'money']:
                if hasattr(pc, stat):
                    setattr(pc, stat, 99999)
            for attr in pc.__dict__:
                if attr.startswith('first_') and getattr(pc, attr) == 'None':
                    setattr(pc, attr, 'Someone')
            pc.choices = [c for c in pc.choices if "fail" not in str(c).lower() and "reject" not in str(c).lower()]
            for flag in ["exam 1 pass", "exam 2 pass"]:
                if flag not in pc.choices:
                    pc.choices.append(flag)
            for skill in ['reading', 'money', 'knowledge', 'lewdness', 'voyeurism', 'affection']:
                skill_str = "Skill: " + skill
                if skill_str not in pc.choices:
                    pc.choices.append(skill_str)
        
        if hasattr(store, 'random_events_list'):
            store.random_events_seen = list(store.random_events_list)
        
        if hasattr(store, 'day'):
            store.day = 100
        
        for flag in ['subject_physics', 'BFF_bicurious', 'PJ', 'studied_in_library']:
            if hasattr(store, flag) and not getattr(store, flag):
                setattr(store, flag, True)
        
        if hasattr(store, 'phone_background_list'):
            for name in store.__dict__:
                if name.startswith("background_list_"):
                    bg_list = getattr(store, name)
                    if isinstance(bg_list, list):
                        for bg in bg_list:
                            if bg not in store.phone_background_list:
                                store.phone_background_list.append(bg)
        
        renpy.restart_interaction()


screen replay_character_side():
    tag menu
    add "replay_bg"

    vpgrid:
        cols 3
        yfill True
        draggable True
        mousewheel True
        scrollbars "vertical"
        pagekeys True
        allow_underfull True
        xspacing 333
        yspacing 233
        xpos 0.0875
        ypos 0.11

        imagebutton auto "replay/thumbnail mei %s.jpg" at button_highlight:
            action ShowMenu("replay_gallery_mei")
            xalign 0.5
            yalign 0.5

        imagebutton auto "replay/thumbnail harriet %s.jpg" at button_highlight:
            action ShowMenu("replay_gallery_harriet")
            xalign 0.5
            yalign 0.5

        if alex.scenes >= 1:
            imagebutton auto "replay/thumbnail alex %s.jpg" at button_highlight:
                action ShowMenu("replay_gallery_alex")
                xalign 0.5
                yalign 0.5
        else:
            vbox xalign 0.5 yalign 0.5:
                image "replay_locked" at locked_button_crop

        if ap.scenes >= 1:
            imagebutton auto "replay/thumbnail april %s.jpg" at button_highlight:
                action ShowMenu("replay_gallery_april")
                xalign 0.5
                yalign 0.5
        else:
            vbox xalign 0.5 yalign 0.5:
                image "replay_locked" at locked_button_crop

        if em.scenes >= 1:
            imagebutton auto "replay/thumbnail emily %s.jpg" at button_highlight:
                action ShowMenu("replay_gallery_emily")
                xalign 0.5
                yalign 0.5
        else:
            vbox xalign 0.5 yalign 0.5:
                image "replay_locked" at locked_button_crop

        if fr.scenes >= 1:
            imagebutton auto "replay/thumbnail freya %s.jpg" at button_highlight:
                action ShowMenu("replay_gallery_freya")
                xalign 0.5
                yalign 0.5
        else:
            vbox xalign 0.5 yalign 0.5:
                image "replay_locked" at locked_button_crop

        if l.scenes >= 1:
            imagebutton auto "replay/thumbnail katie %s.jpg" at button_highlight:
                action ShowMenu("replay_gallery_katie")
                xalign 0.5
                yalign 0.5
        else:
            vbox xalign 0.5 yalign 0.5:
                image "replay_locked" at locked_button_crop

        if lg.scenes >= 1:
            imagebutton auto "replay/thumbnail library girl %s.jpg" at button_highlight:
                action ShowMenu("replay_gallery_library_girl")
                xalign 0.5
                yalign 0.5
        else:
            vbox xalign 0.5 yalign 0.5:
                image "replay_locked" at locked_button_crop

        if mad.scenes >= 1:
            imagebutton auto "replay/thumbnail madelline %s.jpg" at button_highlight:
                action ShowMenu("replay_gallery_madelline")
                xalign 0.5
                yalign 0.5
        else:
            vbox xalign 0.5 yalign 0.5:
                image "replay_locked" at locked_button_crop

        if maple.scenes >= 1:
            imagebutton auto "replay/thumbnail maple %s.jpg" at button_highlight:
                action ShowMenu("replay_gallery_maple")
                xalign 0.5
                yalign 0.5
        else:
            vbox xalign 0.5 yalign 0.5:
                image "replay_locked" at locked_button_crop

        if mia.scenes >= 1:
            imagebutton auto "replay/thumbnail mia %s.jpg" at button_highlight:
                action ShowMenu("replay_gallery_mia")
                xalign 0.5
                yalign 0.5
        else:
            vbox xalign 0.5 yalign 0.5:
                image "replay_locked" at locked_button_crop

        if suzy.scenes >= 1:
            imagebutton auto "replay/thumbnail suzy %s.jpg" at button_highlight:
                action ShowMenu("replay_gallery_suzy")
                xalign 0.5
                yalign 0.5
        else:
            vbox xalign 0.5 yalign 0.5:
                image "replay_locked" at locked_button_crop

        if vns.scenes >= 1:
            imagebutton auto "replay/thumbnail vns %s.jpg" at button_highlight:
                action ShowMenu("replay_gallery_vns")
                xalign 0.5
                yalign 0.5
        else:
            vbox xalign 0.5 yalign 0.5:
                image "replay_locked" at locked_button_crop

        null
        null
        null

    textbutton "{image=arrow_exit} Return":
        action Return()
        xalign 0.5
        yalign 1.0
        background "#000"

    textbutton "{image=arrow_return} Characters":
        action ShowMenu("replay_character")
        xalign 0.1
        yalign 1.0
        background "#000"


screen replay_gallery_mei():
    tag menu
    add "replay_bg"

    grid 3 2:
        xfill True
        yfill True

        for i in range(4):
            if physics_scenes >= i + 1:
                imagebutton idle Replay_items_mei[i].thumbs[0] at button_highlight:
                    action Replay(Replay_items_mei[i].replay, scope=replay_dict, locked=False)
                    xalign 0.5
                    yalign 0.5
            else:
                vbox xalign 0.5 yalign 0.5:
                    image "replay_locked"
        null
        null

    grid 3 2:
        xfill True
        yfill True
        for i in range(4):
            if physics_scenes >= i + 1:
                hbox:
                    spacing maxthumbx - 20
                    xalign 0.5
                    yalign 0.9
                    text Replay_items_mei[i].name
            else:
                null
        null
        null

    textbutton "{image=arrow_exit} Return":
        action Return()
        xalign 0.5
        yalign 1.0
        background "#000"

    textbutton "{image=arrow_return} Side Characters":
        action ShowMenu("replay_character_side")
        xalign 0.1
        yalign 1.0
        background "#000"
