CensoredUsername / unrpyc

A ren'py script decompiler
Other
837 stars 149 forks source link

Odd Decompiling Bug #82

Closed OrdosAlpha closed 4 years ago

OrdosAlpha commented 4 years ago

Encountering an odd decompiling issue involving the tag parameter when decompiling a Ren'Py 7.3.2 screens.rpyc file using UnRPYC 1.0.15. It's being merged into the screen function call.

For example the decompiled code outputs this:-

screen about() tag menu:

When it should be:

screen about():
    tag menu

This results in indentation issues when the decompiled .rpy is re-compiled at game runtime or when executing a re-build.

CensoredUsername commented 4 years ago

Huh. Looking at the responsible code this seems to be intentional even, it hasn't been an issue for 5 years. Maybe ren'py changed behaviour?

I'll change it once I find some time for it.

gadsgadsf commented 4 years ago

Renpy changed behavior in 7.3 https://github.com/renpy/renpy/issues/1860

CensoredUsername commented 4 years ago

Backwards compatibility ain't important it seems, thanks for the headsup!

TetteDev commented 4 years ago

Any update on this issue? Pretty annoying to have to manually fix every file it decompiles.

TetteDev commented 4 years ago

https://github.com/CensoredUsername/unrpyc/blob/master/decompiler/screendecompiler.py#L111

the tag line along with the screen should be decompiled like this

screen myScreen():
    tag myTag

and not

screen myScreen() tag myTag: 
srk68 commented 4 years ago

I just wanted to confirm that the issue is present with Summertime Saga v0.19.1 as well. A fix would be very apprciated :)

TetteDev commented 4 years ago

I just wanted to confirm that the issue is present with Summertime Saga v0.19.1 as well. A fix would be very apprciated :)

For now you have to manually "fix" the affected files https://github.com/CensoredUsername/unrpyc/issues/82#issuecomment-544246177

madeddy commented 4 years ago

@Sadulisten @srk68 You should both add a NSFW tag to you posts for the app... On to the core issue:

Sigh. The issue has gotten worse with newer versions.

If one try's to decompile the above mentioned app in v0.19.5 i got this outcome:

Decompilation of 926 files successful, but decompilation of 269 files failed

The fail's give afaik all the same error:

Error while decompiling ./rpa_extract/scripts/core/user_interface/computer/app/dir.rpyc:
Traceback (most recent call last):
  File "./unrpyc-dev/unrpyc.py", line 164, in worker
    no_pyexpr=args.no_pyexpr, comparable=args.comparable, translator=translator, init_offset=args.init_offset)
  File "./unrpyc-dev/unrpyc.py", line 137, in decompile_rpyc
    translator=translator, init_offset=init_offset)
  File "/home/olli/Code/rpa_tools/unrpyc-dev/decompiler/__init__.py", line 46, in pprint
    decompile_python=decompile_python, translator=translator).dump(ast, indent_level, init_offset)
  File "/home/olli/Code/rpa_tools/unrpyc-dev/decompiler/__init__.py", line 89, in dump
    super(Decompiler, self).dump(ast, indent_level, skip_indent_until_write=True)
  File "/home/olli/Code/rpa_tools/unrpyc-dev/decompiler/util.py", line 29, in dump
    self.print_nodes(ast)
  File "/home/olli/Code/rpa_tools/unrpyc-dev/decompiler/util.py", line 120, in print_nodes
    self.print_node(node)
  File "/home/olli/Code/rpa_tools/unrpyc-dev/decompiler/__init__.py", line 106, in print_node
    self.dispatch.get(type(ast), type(self).print_unknown)(self, ast)
  File "/home/olli/Code/rpa_tools/unrpyc-dev/decompiler/__init__.py", line 590, in print_init
    self.print_nodes(ast.block)
  File "/home/olli/Code/rpa_tools/unrpyc-dev/decompiler/util.py", line 120, in print_nodes
    self.print_node(node)
  File "/home/olli/Code/rpa_tools/unrpyc-dev/decompiler/__init__.py", line 106, in print_node
    self.dispatch.get(type(ast), type(self).print_unknown)(self, ast)
  File "/home/olli/Code/rpa_tools/unrpyc-dev/decompiler/__init__.py", line 848, in print_screen
    self.printlock)
  File "/home/olli/Code/rpa_tools/unrpyc-dev/decompiler/sl2decompiler.py", line 38, in pprint
    ast, indent_level, linenumber, skip_indent_until_write)
  File "/home/olli/Code/rpa_tools/unrpyc-dev/decompiler/util.py", line 29, in dump
    self.print_nodes(ast)
  File "/home/olli/Code/rpa_tools/unrpyc-dev/decompiler/util.py", line 120, in print_nodes
    self.print_node(node)
  File "/home/olli/Code/rpa_tools/unrpyc-dev/decompiler/sl2decompiler.py", line 53, in print_node
    self.dispatch.get(type(ast), type(self).print_unknown)(self, ast)
  File "/home/olli/Code/rpa_tools/unrpyc-dev/decompiler/sl2decompiler.py", line 68, in print_screen
    tag=ast.tag)
  File "/home/olli/Code/rpa_tools/unrpyc-dev/decompiler/sl2decompiler.py", line 304, in print_keywords_and_children
    self.print_nodes(children_after_keywords, 0 if has_block else 1).py
  File "/home/olli/Code/rpa_tools/unrpyc-dev/decompiler/util.py", line 120, in print_nodes
    self.print_node(node)
  File "/home/olli/Code/rpa_tools/unrpyc-dev/decompiler/sl2decompiler.py", line 53, in print_node
    self.dispatch.get(type(ast), type(self).print_unknown)(self, ast)
  File "/home/olli/Code/rpa_tools/unrpyc-dev/decompiler/sl2decompiler.py", line 159, in print_use
    self.print_block(ast.block)
  File "/home/olli/Code/rpa_tools/unrpyc-dev/decompiler/sl2decompiler.py", line 104, in print_block
    self.print_keywords_and_children(ast.keyword, ast.children, None)
  File "/home/olli/Code/rpa_tools/unrpyc-dev/decompiler/sl2decompiler.py", line 304, in print_keywords_and_children
    self.print_nodes(children_after_keywords, 0 if has_block else 1).py
AttributeError: 'NoneType' object has no attribute 'py'

And manually fixing files is very much out of question if one bothers to look at the file count. I hope a bugfix will come soon.

What makes me also worry: RenPy is about to switch to py 3. Who knows what the foo then breaks.

Jaiglissechef-i9100 commented 4 years ago

Dogeek makes sure that we can no longer modulate Summertime Saga. (as much as I've given up, I've done and I'm not worse off.)

I confirm the request pullover is working well. To add "init offset = -xx" at the beginning of these files screen, gui and option.rpy and "init-2 style/screen/etc..." --> "style/screen/etc...", "transform -2" --> "transform" and unrpyc will be less up to date.

CensoredUsername commented 4 years ago

@madeddy That looks like a completely different issue. Could you make a separate bug report for it? I know I haven't had a lot of time to look at this lately but that would help for clarity.

CensoredUsername commented 4 years ago

I've provided a fix on the dev branch, if anyone could confirm it resolves the issues I'll cut a new release.

madeddy commented 4 years ago

No change to the previous trys to decompile as far as i can see. One example:

init python hide:
    '''
    This sets up the exception screen for the Saga metagame on the
    various PCs. It reuses the real Ren'Py exception screen to provide
        a realistic looking screen full of easter eggs.
        '''

from copy import copy
from textwrap import dedent

from renpy.display.screen import ScreenDisplayable, get_screen_variant
from renpy.store import Fixed, NullAction, Transform

from store.util import struct

stack = dedent('''\
        While running game code:
              File "game/bedroom.rpy", line 12, in script call
                call click()
              File "game/bedroom.rpy", line 26, in script
                call screen bedroom()
              File "renpy/common/000statements.rpy", line 531, in execute_call_screen
                store._return = renpy.call_screen(name, *args, **kwargs)
            NameError: name 'click' is not defined
        ''')

error = dedent('''\
        Message DarkCookie if you have received this error.
            (He loves bug reports)
        ''')

noop = NullAction()

scope = {'config': struct(version='0.0.7-goldeneye', developer=False),
             'renpy': struct(platform='AsbestOS-3.1', version_only='6.99.11'),
             'full': error,
             'ignore_action': noop,
             'reload_action': noop,
             'rollback_action': noop,
             'short': stack,
             'traceback_fn': None}

scr = copy(get_screen_variant('_exception')) 
scr.modal = 'False'
scr.sensitive = 'False'

d = ScreenDisplayable(scr, None, None, scope=scope)

renpy.image('pc_saga_ex', Transform(Fixed(d, xysize=(800, 525)), zoom=.64))
# Decompiled by unrpyc: https://github.com/CensoredUsername/unrpyc

Code isn't indented. Or is this a different issue? RenPy: errors.zip

CensoredUsername commented 4 years ago

@madeddy this issue is for the screen tag bug, this is again a different issue. Could you make a different issue and attach the .rpyc file so I can figure out why indentation is getting lost there? It probably has to do with the multiline docstrings, ren'py used to not support those.

Jaiglissechef-i9100 commented 4 years ago

I test ur fix, and i return the result.

Edit: For the tag, it's good

My decompil with ur fix init -501 screen save(): tag menu

CensoredUsername commented 4 years ago

Seems to be fixed.