unrpyc

repository·master·Indexed 22 days ago

https://github.com/censoredusername/unrpyc

A specialized decompiler for Ren'Py compiled (.rpyc) script files that recovers readable Python-based Ren'Py scripts. It features a CLI for decompilation, translation support via the -t flag, AST dumping, and the ability to inject the decompiler directly into a running game. The tool is split into two branches: v2 (master) for Ren'Py 8.x and Python 3.9+, and v1 (legacy) for Ren'Py 7.x/6.x and Python 2.7.

Tokens
2.1K
Snippets
4
Records
14
Agent score
79%

What's inside unrpyc

  1. Choose the correct unrpyc version for Ren'Py compatibility

    master

    Because Ren'Py transitioned from Python 2 to Python 3 (in Ren'Py 8), unrpyc is split into two distinct branches. Choosing the wrong version will result in failure.

    unrpyc v2 (master branch)

    • Python Requirement: 3.9 or above.
    • Ren'Py Support: Ren'Py 8.x (most recent) down to 6.18.0.
    • Note: For games between 6.18.0 and 6.99.10, you must use the --no-init-offset option.
    • Injectors: Only supports Ren'Py 8.x.

    unrpyc v1 (legacy branch)

    • Python Requirement: 2.7.
    • Ren'Py Support: Ren'Py 7.x and 6.x.
    • Injectors: Supports Ren'Py 6.x and 7.x.

    Note: Ren'Py 5 or earlier are not supported.

  2. Requesting deobfuscation support

    master

    The tool includes a basic framework for deobfuscation to counter modifications in the Ren'Py file format. However, the maintainers do not actively pursue feature requests for specific game deobfuscation due to the 'arms race' nature of obfuscation.

    If you have implemented deobfuscation support for a specific game, you are encouraged to submit a pull request. The maintainers may merge it into the mainline or a game-specific branch depending on its utility.

  3. Dump raw AST instead of decompiling

    master

    If you need to see the raw Abstract Syntax Tree (AST) instead of decompiled code (useful for debugging or bug reports), use the -d or --dump flag.

    Warning: This generates a significant amount of output.

    Related flags for dumping:

    • --comparable: Removes false differences (like file modification times) when comparing dumps.
    • --no-pyexpr: Disables special handling of PyExpr objects, printing them as strings instead. This is useful for comparing dumps across different Ren'Py versions but results in a loss of information like line numbers.
  4. Translate decompiled scripts to a specific language

    master

    You can automatically convert decompiled script files to a different language using translation data already present in the game's game/tl folder.

    To use this, identify the target language name in the game/tl directory and pass it using the -t or --translate option.

    Example: If the game has a translation folder at path/to/renpyapp/game/tl/french, run: python unrpyc.py /path/to/renpyapp/ -t french

    python unrpyc.py /path/to/renpyapp/ -t french
  5. Inject unrpyc directly into a Ren'Py game

    master

    You can inject the decompiler directly into a running game to automatically extract and decompile all game script files into the game directory.

    Steps:

    1. Identify your Ren'Py version (8.x vs 7/6).
    2. Download the corresponding injector (un.rpyc or bytecode.rpyb) from the latest release.
    3. Place the file into the game directory of the Ren'Py game.
    4. Run the game.

    The tool will write logs to unrpyc.log.txt in the game directory.

  6. Compile un.rpyc for automatic game decompilation

    master

    To create un.rpyc, a file that automatically decompiles a Ren'Py game when loaded, run the compile.py script using Python 3.9 or above.

    un.rpyc works by exploiting the fact that .rpyc files are gzip-compressed pickle files. It uses the pickleast module to create a pickle that executes the decompiler during the Ren'Py loading process, before any .rpy code runs.

  7. Decompile Ren'Py scripts using the CLI

    master

    To decompile .rpyc files into readable .rpy scripts, run unrpyc.py via Python and provide the target files or directories as arguments. By default, the tool will not overwrite existing .rpy files.

    Basic Usage:

    • Decompile specific files: python unrpyc.py file1.rpyc file2.rpyc
    • Decompile an entire folder: python unrpyc.py folder/

    Requirements:

    • A local Python installation.
    • The unrpyc.py file must be in the same directory as the modules directory for the script to run correctly.
    python unrpyc.py file1.rpyc file2.rpyc
    # or
    python unrpyc.py folder/
  8. Validate decompiled output against expected results

    master

    The testcases directory contains originals (.rpy), compiled (.rpyc), and expected (.rpy) files. Because .rpyc files do not contain enough data to reconstruct original files perfectly, the expected folder contains manually verified outputs.

    You can use the provided validate_expected.py script to verify decompiled results. The script strips out comments and empty lines to facilitate comparison. To update the expected folder with new decompiled files from the compiled folder, run the script with the --update flag.

  9. Troubleshoot decompilation errors

    master

    If the decompiler fails to process a .rpyc file, follow these steps before reporting an issue:

    1. Isolate the tool: Test the .rpyc files directly using the command line tool and both game injection methods. Do not use third-party wrapper tools that incorporate unrpyc for your troubleshooting.
    2. Use anti-obfuscation mode: Run the command line tool with the --try-harder flag to attempt to bypass obfuscation layers.
  10. Submit an issue report to unrpyc

    master

    When reporting a bug where decompilation fails, ensure your report includes the following information to avoid being asked for missing details:

    1. Versions: The version of unrpyc being used and the version of Ren'Py used to create the .rpyc file (and the name of the game, if applicable).
    2. Problem Description: A clear explanation of the issue (e.g., does it fail to decompile entirely, is there an omission in the output, or is the resulting file invalid?).
    3. Logs: Attach the full command line output produced by the tool.
    4. Files: Attach the specific .rpyc file that is failing to decompile.

    All reports should be written in legible English.

  11. Use unrpyc as a Python library

    master

    You can import the module and call the decompile function directly in your Python code.

    Warning: This interface is under active development and behavior has changed with the transition to Python 3. Use with caution.

    import unrpyc
    # Call the decompile function directly
    unrpyc.decompile_rpyc(filename, ...)