unrpyc icon indicating copy to clipboard operation
unrpyc copied to clipboard

RevertableDict (not fixed with set)

Open Bexa2 opened this issue 3 years ago β€’ 4 comments

With python 3.10, the games uses RenPy 8.0.0

 File "G:\decompilers\rpa_decompiler\unrpyc.py", line 170, in read_ast_from_file
   data, stmts = magic.safe_loads(
 File "G:\decompilers\rpa_decompiler\decompiler\magic.py", line 718, in safe_loads
   ).load()
 File "C:\Users\Bexa\AppData\Local\Programs\Python\Python310\lib\pickle.py", line 1275, in load
   dispatch[key[0]](self)
 File "C:\Users\Bexa\AppData\Local\Programs\Python\Python310\lib\pickle.py", line 1824, in load_setitem
   dict[key] = value
ypeError: 'RevertableDict' object does not support item assignment
dict=<renpy.revertable.RevertableDict object at 0x00000196409684F0>
key='delay'
value=None

It fails at script.rpyc, attached a zip with the file that fails.

script.zip

Here's my class_factory

class_factory = magic.FakeClassFactory(
    (
        frozenset,
        PyExpr,
        PyCode,
        RevertableList,
        RevertableDict,
        RevertableSet,
        Sentinel,
        set,
    ),
    magic.FakeStrict,
)

Update, changed renpy.python to renpy.revertable Now it fails at load_setitems


[...]

dict={'hide': False, 'name': '_call_releaseNotes_1', 'parameters': None, 'filename': 'game/script.rpy', 'linenumber': 13, 'next': None}
items=['hide', False, 'name', '_call_releaseNotes_1', 'parameters', None, 'filename', 'game/script.rpy', 'linenumber', 13, 'next', None, 'block', []]
items[i]='block'
items[i+1]=[]
dict={}
items=['next', None, 'linenumber', 13, 'name', ('game/script.rpy', 1610606469, 15), 'filename', 'game/script.rpy']
items[i]='next'
items[i+1]=None
dict={'next': None}
items=['next', None, 'linenumber', 13, 'name', ('game/script.rpy', 1610606469, 15), 'filename', 'game/script.rpy']
items[i]='linenumber'
items[i+1]=13
dict={'next': None, 'linenumber': 13}
items=['next', None, 'linenumber', 13, 'name', ('game/script.rpy', 1610606469, 15), 'filename', 'game/script.rpy']
items[i]='name'
items[i+1]=('game/script.rpy', 1610606469, 15)
dict={'next': None, 'linenumber': 13, 'name': ('game/script.rpy', 1610606469, 15)}
items=['next', None, 'linenumber', 13, 'name', ('game/script.rpy', 1610606469, 15), 'filename', 'game/script.rpy']
items[i]='filename'
items[i+1]='game/script.rpy'
dict=<renpy.python.RevertableDict object at 0x00000204E17011B0>
items=[b'predict', True, b'arguments', None, b'transition_expr', None, b'name', 'patreon']
items[i]=b'predict'
items[i+1]=True

Traceback (most recent call last):
  File "G:\normalize_paths.py", line 567, in <module>
    main()
  File "G:\normalize_paths.py", line 563, in main
    fix_games(path, type_of_game)
  File "G:\normalize_paths.py", line 541, in fix_games
    raise e
  File "G:\normalize_paths.py", line 538, in fix_games
    (name, version) = get_name_and_version(path)
  File "G:\normalize_paths.py", line 137, in renpy_get_name_and_version
    raise err
  File "G:\normalize_paths.py", line 124, in renpy_get_name_and_version
    ret = unrpyc.decompile_rpyc(file)
  File "G:\decompilers\rpa_decompiler\unrpyc.py", line 211, in decompile_rpyc
    ast = read_ast_from_file(in_file, encoding=encoding)
  File "G:\decompilers\rpa_decompiler\unrpyc.py", line 170, in read_ast_from_file
    data, stmts = magic.safe_loads(
  File "G:\decompilers\rpa_decompiler\decompiler\magic.py", line 718, in safe_loads
    ).load()
  File "C:\Users\Bexa\AppData\Local\Programs\Python\Python310\lib\pickle.py", line 1275, in load
    dispatch[key[0]](self)
  File "C:\Users\Bexa\AppData\Local\Programs\Python\Python310\lib\pickle.py", line 1836, in load_setitems
    dict[items[i]] = items[i + 1]
TypeError: 'RevertableDict' object does not support item assignment

Bexa2 avatar Aug 02 '22 19:08 Bexa2

Having everything as renpy.python seems to get further before crashing (my added prints print 2000 lines vs 9000 lines)

dict={'expr': 'fade', 'paired': None, 'name': ('game/script.rpy', 1658182085, 13), 'filename': 'game/script.rpy', 'linenumber': 80}
items=['expr', 'fade', 'paired', None, 'name', ('game/script.rpy', 1658182085, 13), 'filename', 'game/script.rpy', 'linenumber', 80, 'next', None]
items[i]='next'
items[i+1]=None
dict=<renpy.revertable.RevertableDict object at 0x000001BB278114E0>
key='delay'
value=None

Bexa2 avatar Aug 02 '22 20:08 Bexa2

Same error message with game using Python 3.9. Game: VIS 2.0 Script: script.rpyc (other as well but this one is little) file game available under https://dikgames.com/vis/ (season 2 so not too big)

script.rpyc.zip

MARLBORO-NEW avatar Oct 06 '22 17:10 MARLBORO-NEW

Other game with 2.7 python base: Helping hotites (https://dikgames.com/helping-the-hotties hh.zip

MARLBORO-NEW avatar Oct 18 '22 17:10 MARLBORO-NEW

Might test with solution on post: https://github.com/CensoredUsername/unrpyc/issues/156#issue-1416743346

Works with python 2.7

MARLBORO-NEW avatar Oct 20 '22 14:10 MARLBORO-NEW

  1. This should be in a way a duplicate of #146
  2. In the opener post of user @Bexa2 the tool complains two times about File "G:\decompilers\rpa_decompiler\decompiler\magic.py", line 718, in safe_loads).load(). In line 718! The magic.py of the last version 1.1.8 has however only 674 lines.

Whatsoever version of unrpyc used was, makes every try of others to understand the code a waste of time.

madeddy avatar Nov 08 '22 23:11 madeddy

  1. This should be in a way a duplicate of RenPy 7.5.0 changesΒ #146
  2. In the opener post of user @Bexa2 the tool complains two times about File "G:\decompilers\rpa_decompiler\decompiler\magic.py", line 718, in safe_loads).load(). In line 718! The magic.py of the last version 1.1.8 has however only 674 lines.

Whatsoever version of unrpyc used was, makes every try of others to understand the code a waste of time.

Actually, #156 did fix my errors (on the games I tested), #146 was not enough.

As for the number of lines, black formatted on save, so my file has more lines.

Bexa2 avatar Nov 09 '22 00:11 Bexa2

Thanks for clearing this. It was confusing. Formaters can be a gift and hell at the same time. 😜

Did you use the whole of the changes form #156? @sigio uses in his pull request the change magic.py line 112 replace "if args or kwargs:" with "if (args or kwargs) and args != ([],) and kwargs != {}:" not, so i'am unsure if its needed. I noticed no problems only with the other corrections.

Greets

madeddy avatar Nov 09 '22 00:11 madeddy

Thanks for clearing this. It was confusing. Formaters can be a gift and hell at the same time. 😜

Did you use the whole of the changes form #156? @sigio uses in his pull request the change magic.py line 112 replace "if args or kwargs:" with "if (args or kwargs) and args != ([],) and kwargs != {}:" not, so i'am unsure if its needed. I noticed no problems only with the other corrections.

Greets

Yeah, I have a comment on that pull requests, those changes made it so it worked on one game and stopped working on another.

I think the change in magic.py is what made it work in both games.

Bexa2 avatar Nov 09 '22 00:11 Bexa2

I think the change in magic.py is what made it work in both games.

Interesting. Ok, thanks. I will test this and see. πŸ‘‹πŸ»

madeddy avatar Nov 09 '22 01:11 madeddy

I think the change in magic.py is what made it work in both games.

Interesting. Ok, thanks. I will test this and see. πŸ‘‹πŸ»

I just tried OnthePrairie-0.3.0-pc and it gave me the error

G:\f95zone\todo\OnthePrairie-0.3.0-pc\temp_folder\script.rpyc
Failed at G:\f95zone\todo\OnthePrairie-0.3.0-pc
Traceback (most recent call last):
  File "G:\f95zone\normalize_paths.py", line 576, in <module>
    main()
  File "G:\f95zone\normalize_paths.py", line 572, in main
    fix_games(f95zone_path, type_of_game)
  File "G:\f95zone\normalize_paths.py", line 550, in fix_games
    raise e
  File "G:\f95zone\normalize_paths.py", line 547, in fix_games
    (name, version) = get_name_and_version(path)
  File "G:\f95zone\normalize_paths.py", line 137, in renpy_get_name_and_version
    raise err
  File "G:\f95zone\normalize_paths.py", line 124, in renpy_get_name_and_version
    ret = unrpyc.decompile_rpyc(file)
  File "G:\f95zone\decompilers\rpa_decompiler\unrpyc.py", line 211, in decompile_rpyc
    ast = read_ast_from_file(in_file, encoding=encoding)
  File "G:\f95zone\decompilers\rpa_decompiler\unrpyc.py", line 170, in read_ast_from_file
    data, stmts = magic.safe_loads(
  File "G:\f95zone\decompilers\rpa_decompiler\decompiler\magic.py", line 718, in safe_loads
    ).load()
  File "C:\Users\Bexa2\miniconda3\envs\f95zone\lib\pickle.py", line 1213, in load
    dispatch[key[0]](self)
  File "C:\Users\Bexa2\miniconda3\envs\f95zone\lib\pickle.py", line 1691, in load_setitem
    dict[key] = value
TypeError: 'RevertableDict' object does not support item assignment

Just by changing

class RevertableDict(magic.FakeStrict, dict):
    __module__ = "renpy.revertable"

to

class RevertableDict(magic.FakeStrict, dict):
    __module__ = "renpy.python"

fixed it (Of course some other game will need the renpy.revertable in the future so I'll have to manually switch between the two), so it'd be nice to be able to use both, for new and old games.

Bexa2 avatar Nov 09 '22 12:11 Bexa2

Ahem... just a thought.. Which version has the game you used here? And if we're on it, which v. have the others you tested, where you changed back to renpy.python?

renpy.revertable should only be needed and actually working with Ren'py 7.5.x and 8.x. Just making sure nothing is accidentally overlooked.

btw.: The code change in magic.py is indeed also needed from the look of it. The pull request for the changes has it missing, but needs it to be complete.

madeddy avatar Nov 09 '22 13:11 madeddy

This is also fixed. Problems arises not from Ren'Py v8 but from the revertable issue.

madeddy avatar Feb 20 '24 17:02 madeddy

This is working on dev right now.

CensoredUsername avatar Feb 22 '24 02:02 CensoredUsername

Should be fixed on master and releases as well now, so closing πŸŽ‰

CensoredUsername avatar Mar 06 '24 02:03 CensoredUsername