CensoredUsername / unrpyc

A ren'py script decompiler
Other
864 stars 157 forks source link

Special-cased keywords in screens aren't handled correctly #23

Closed jackmcbarn closed 9 years ago

jackmcbarn commented 9 years ago

Given the following original .rpy:

screen testScreen:
    variant "Small"
    zorder 0
    modal False
screen testScreen2:
    variant "Small"
    modal False
    zorder 0
screen testScreen3:
    zorder 0
    variant "Small"

When compiled, here's the relevant bits of the dump:

[
    <renpy.ast.Init 
        .block = [<renpy.ast.Screen 
            .screen = <renpy.sl2.slast.SLScreen 
                .keyword = [
                    (
                        u'variant',
                        u'"Small"'
                    ),
                    (
                        u'zorder',
                        u'0'
                    ),
                    (
                        u'modal',
                        u'False'
                    )
                ],
                .modal = u'False',
                .name = u'testScreen',
                .predict = 'None',
                .tag = None,
                .variant = u'"Small"',
                .zorder = u'0'
            >
        >]
    >,
    <renpy.ast.Init 
        .block = [<renpy.ast.Screen 
            .screen = <renpy.sl2.slast.SLScreen 
                .keyword = [
                    (
                        u'variant',
                        u'"Small"'
                    ),
                    (
                        u'modal',
                        u'False'
                    ),
                    (
                        u'zorder',
                        u'0'
                    )
                ],
                .modal = u'False',
                .name = u'testScreen2',
                .predict = 'None',
                .tag = None,
                .variant = u'"Small"',
                .zorder = u'0'
            >
        >]
    >,
    <renpy.ast.Init 
        .block = [<renpy.ast.Screen 
            .screen = <renpy.sl2.slast.SLScreen 
                .keyword = [
                    (
                        u'zorder',
                        u'0'
                    ),
                    (
                        u'variant',
                        u'"Small"'
                    )
                ],
                .modal = 'False',
                .name = u'testScreen3',
                .predict = 'None',
                .tag = None,
                .variant = u'"Small"',
                .zorder = u'0'
            >
        >]
    >
]

Note that the original presence or absence, and order, of each keyword is maintained in .keywords. Here's the result when decompiled back to source:

screen testScreen:
    modal False
    variant "Small"
screen testScreen2:
    modal False
    variant "Small"
screen testScreen3:
    modal False
    variant "Small"

The information about ordering of the keywords, as well as presence or absence of default values, has been lost. (I assume this happens with tag and predict as well).

CensoredUsername commented 9 years ago

This is a remnant of screen language one parsing where those keywords were only recorded as attributes on the screen object with no way of figuring out what order they were in or if they were default values.

I've fixed this now, but I'm first trying to find a better solution for keyword argument parsing to fix #24.