rpx-kit 0.2.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of rpx-kit might be problematic. Click here for more details.
- rpx_kit/__init__.py +1 -0
- rpx_kit/cli.py +119 -0
- rpx_kit/core.py +64 -0
- rpx_kit-0.2.3.dist-info/METADATA +109 -0
- rpx_kit-0.2.3.dist-info/RECORD +8 -0
- rpx_kit-0.2.3.dist-info/WHEEL +4 -0
- rpx_kit-0.2.3.dist-info/entry_points.txt +2 -0
- rpx_kit-0.2.3.dist-info/licenses/LICENSE +21 -0
rpx_kit/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.2.1"
|
rpx_kit/cli.py
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import sys
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from time import time
|
|
5
|
+
|
|
6
|
+
from rpx_kit import __version__
|
|
7
|
+
|
|
8
|
+
from .core import filter_index, read_index, unpack_rpa
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def validate_input_path(path: str) -> list[Path]:
|
|
12
|
+
path_obj = Path(path)
|
|
13
|
+
if path_obj.is_file() and path_obj.suffix.lower() == ".rpa":
|
|
14
|
+
return [path_obj]
|
|
15
|
+
elif path_obj.exists() and path_obj.is_dir():
|
|
16
|
+
result = scan_folder(path_obj)
|
|
17
|
+
if not result:
|
|
18
|
+
print(f"Warning! No RPA archives found in {path}", file=sys.stderr)
|
|
19
|
+
return []
|
|
20
|
+
else:
|
|
21
|
+
return result
|
|
22
|
+
else:
|
|
23
|
+
print(f"Not a valid RPA file or directory: {path}", file=sys.stderr)
|
|
24
|
+
return []
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def validate_output_path(path: str) -> Path:
|
|
28
|
+
path_obj = Path(path)
|
|
29
|
+
if path_obj.exists() and not path_obj.is_dir():
|
|
30
|
+
raise argparse.ArgumentTypeError(
|
|
31
|
+
f"Output path exists but is not a directory: {path}"
|
|
32
|
+
)
|
|
33
|
+
else:
|
|
34
|
+
return path_obj
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def scan_folder(path_obj: Path) -> list[Path]:
|
|
38
|
+
scan = list(path_obj.rglob("*.rpa"))
|
|
39
|
+
return scan
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
parser = argparse.ArgumentParser(prog="rpx-kit")
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
parser.add_argument("input_paths", nargs="*", help="Path to the RPA-3.0 archive")
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
parser.add_argument(
|
|
49
|
+
"-o", "--output", dest="output_path", type=validate_output_path, help="Output path"
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
parser.add_argument(
|
|
54
|
+
"-l",
|
|
55
|
+
"--list",
|
|
56
|
+
action="store_true",
|
|
57
|
+
help="Prints a list of files inside the archive",
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
parser.add_argument(
|
|
62
|
+
"-m",
|
|
63
|
+
"--mask",
|
|
64
|
+
action="append",
|
|
65
|
+
dest="masks",
|
|
66
|
+
default=None,
|
|
67
|
+
help="Filter by mask, can be repeated: -m '*.rpyc' -m '*.png'",
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
parser.add_argument(
|
|
72
|
+
"-v", "--version", action="version", version=f"%(prog)s {__version__}"
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def main():
|
|
77
|
+
args = parser.parse_args()
|
|
78
|
+
if not args.input_paths:
|
|
79
|
+
raise argparse.ArgumentTypeError("No paths provided")
|
|
80
|
+
input_paths = [validate_input_path(path) for path in args.input_paths]
|
|
81
|
+
if input_paths:
|
|
82
|
+
archives = [path for paths in input_paths for path in paths]
|
|
83
|
+
print(f"{len(archives)} archives found")
|
|
84
|
+
else:
|
|
85
|
+
raise argparse.ArgumentTypeError("No valid paths provided")
|
|
86
|
+
start_time = time()
|
|
87
|
+
for archive in archives:
|
|
88
|
+
print(
|
|
89
|
+
f"Processing {archive}, total size = {round(archive.stat().st_size / (1024 * 1024), 2)} MB"
|
|
90
|
+
)
|
|
91
|
+
with open(archive, "rb") as file:
|
|
92
|
+
try:
|
|
93
|
+
index = read_index(file)
|
|
94
|
+
except Exception as e:
|
|
95
|
+
print(f"Skip {archive}, error: {e}", file=sys.stderr)
|
|
96
|
+
continue
|
|
97
|
+
if args.masks:
|
|
98
|
+
index = filter_index(index, args.masks)
|
|
99
|
+
if not index:
|
|
100
|
+
print(f"No files match the given mask in {archive}")
|
|
101
|
+
continue
|
|
102
|
+
if args.list:
|
|
103
|
+
for filename in sorted(index.keys()):
|
|
104
|
+
print(f"{filename}")
|
|
105
|
+
else:
|
|
106
|
+
if args.output_path is None:
|
|
107
|
+
parser.error("-o/--output is required when unpacking")
|
|
108
|
+
output_dir = args.output_path / archive.stem
|
|
109
|
+
output_dir.mkdir(parents=True, exist_ok=True)
|
|
110
|
+
total = unpack_rpa(file, index, output_dir)
|
|
111
|
+
|
|
112
|
+
print(f"Done, {archive} processed")
|
|
113
|
+
print(f"Total files extracted: {total}")
|
|
114
|
+
end_time = time()
|
|
115
|
+
print(f"Time taken: {end_time - start_time:.2f} seconds")
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
if __name__ == "__main__":
|
|
119
|
+
main()
|
rpx_kit/core.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import io
|
|
2
|
+
import pickle
|
|
3
|
+
import zlib
|
|
4
|
+
from fnmatch import fnmatch
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import BinaryIO
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class SafeUnpickler(pickle.Unpickler):
|
|
10
|
+
def find_class(self, module_name, global_name):
|
|
11
|
+
raise pickle.UnpicklingError("Import is prohibited")
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def read_index(infile: BinaryIO) -> dict:
|
|
15
|
+
header = infile.read(33)
|
|
16
|
+
if not header.startswith(b"RPA-3.0 "):
|
|
17
|
+
raise ValueError("Unsupported format")
|
|
18
|
+
offset, key = int(header[8:24], 16), int(header[25:33], 16)
|
|
19
|
+
infile.seek(offset)
|
|
20
|
+
virtual_file = io.BytesIO(zlib.decompress(infile.read()))
|
|
21
|
+
index = SafeUnpickler(virtual_file).load()
|
|
22
|
+
|
|
23
|
+
for filename in index:
|
|
24
|
+
# index = Dict[str, List[Tuple[int, int, bytes]]]
|
|
25
|
+
# Key = filename
|
|
26
|
+
# Values = list of chunks (offset, length, bytes)
|
|
27
|
+
# Bytes never used in RPA 3.0
|
|
28
|
+
offset, length = index[filename][0][0], index[filename][0][1]
|
|
29
|
+
index[filename] = (offset ^ key, length ^ key)
|
|
30
|
+
return index
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def filter_index(index: dict, masks: list):
|
|
34
|
+
if not masks:
|
|
35
|
+
return index
|
|
36
|
+
return {
|
|
37
|
+
filename: data
|
|
38
|
+
for filename, data in index.items()
|
|
39
|
+
if any(_match(filename, mask) for mask in masks)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _match(filename: str, mask: str) -> bool:
|
|
44
|
+
return fnmatch(filename, mask) or fnmatch(Path(filename).name, mask)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def extract_file(infile: BinaryIO, output_path: Path, file_data: tuple) -> None:
|
|
48
|
+
offset, length = file_data
|
|
49
|
+
with open(output_path, "wb") as out_file:
|
|
50
|
+
infile.seek(offset)
|
|
51
|
+
data = infile.read(length)
|
|
52
|
+
out_file.write(data)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def unpack_rpa(infile: BinaryIO, index: dict, target_path: Path) -> int:
|
|
56
|
+
total = 0
|
|
57
|
+
unique_dirs = {target_path / Path(filename).parent for filename in index}
|
|
58
|
+
for directory in unique_dirs:
|
|
59
|
+
directory.mkdir(parents=True, exist_ok=True)
|
|
60
|
+
for filename, file_data in index.items():
|
|
61
|
+
output_file = target_path / filename
|
|
62
|
+
extract_file(infile, output_file, file_data)
|
|
63
|
+
total += 1
|
|
64
|
+
return total
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: rpx-kit
|
|
3
|
+
Version: 0.2.3
|
|
4
|
+
Summary: Toolkit for Ren'Py RPA 3.0 archives
|
|
5
|
+
Author: Padorublad3
|
|
6
|
+
License: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Python: >=3.11
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
|
|
11
|
+
# RPX-KIT
|
|
12
|
+
[](https://github.com/Padorublad3/rpx-kit/actions/workflows/pylint.yml)
|
|
13
|
+
[](https://github.com/astral-sh/ruff)
|
|
14
|
+
[](https://www.python.org/downloads/)
|
|
15
|
+
[](https://opensource.org/licenses/MIT)
|
|
16
|
+
## Description
|
|
17
|
+
A toolkit for extracting or viewing only RPA-3.0 archives made with Renpy
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
## Features
|
|
21
|
+
**Safe Unpickling**. Uses a custom SafeUnpickler that blocks all external imports during deserialization.
|
|
22
|
+
|
|
23
|
+
**Zero Dependencies**.
|
|
24
|
+
|
|
25
|
+
**CLI Mask Filtering**. Filter files directly using shell-style patterns (e.g., -m "*.png"). Extract or list only what you need without dumping the entire archive to disk first.
|
|
26
|
+
|
|
27
|
+
**Cross-Platform**. Works identically on Windows, Linux, and macOS. Path handling is abstracted via pathlib, so no slash-related issues.
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
## Installation
|
|
31
|
+
> [!NOTE]
|
|
32
|
+
> **Python >= 3.11** is required
|
|
33
|
+
|
|
34
|
+
Via pip
|
|
35
|
+
```bash
|
|
36
|
+
pip install git+https://github.com/Padorublad3/rpx-kit.git
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
## Usage
|
|
41
|
+
```
|
|
42
|
+
rpx-kit [-l | -o DIR] [-m PATTERN]... INPUT_PATH
|
|
43
|
+
|
|
44
|
+
Arguments:
|
|
45
|
+
INPUT_PATHS Input .rpa archive(s) files or directory
|
|
46
|
+
|
|
47
|
+
Options:
|
|
48
|
+
-l, --list Print list of files contained in the archive
|
|
49
|
+
-o, --output Target directory for extraction (creates if missing)
|
|
50
|
+
-m, --mask Filter by fnmatch pattern (repeatable, e.g., -m "*.png")
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
## Examples
|
|
55
|
+
List all PNG and JPG files:
|
|
56
|
+
```bash
|
|
57
|
+
rpx-kit mygame/archive.rpa -m "*.png" -m "*.jpg" -l
|
|
58
|
+
```
|
|
59
|
+
Save the list to a text file:
|
|
60
|
+
```bash
|
|
61
|
+
rpx-kit mygame/archive.rpa -m "*.png" -m "*.jpg" -l > result.txt
|
|
62
|
+
```
|
|
63
|
+
Extract only PNG and JPG files to a folder:
|
|
64
|
+
```bash
|
|
65
|
+
rpx-kit mygame/archive.rpa -m "*.png" -m "*.jpg" -o destination_folder
|
|
66
|
+
|
|
67
|
+
rpx-kit mygame/archive.rpa mygame/archive2.rpa -m "*.png" -m "*.jpg" -o destination_folder
|
|
68
|
+
|
|
69
|
+
rpx-kit mygame -m "*.png" -m "*.jpg" -o destination_folder
|
|
70
|
+
```
|
|
71
|
+
## Mask Cheat Sheet
|
|
72
|
+
|
|
73
|
+
Masks use standard shell-style patterns (`fnmatch`). Remember to wrap them in quotes!
|
|
74
|
+
|
|
75
|
+
| Pattern | Meaning | Example Match |
|
|
76
|
+
| :--- | :--- | :--- |
|
|
77
|
+
| `*` | Matches **any sequence** of characters (including none) | `*.png` → `image.png`, `bg/day.png` |
|
|
78
|
+
| `?` | Matches exactly **one** character | `img?.png` → `img1.png`, but NOT `img10.png` |
|
|
79
|
+
| `[abc]` | Matches **one** char from the set | `file[123].txt` → `file1.txt`, `file2.txt` |
|
|
80
|
+
| `[a-z]` | Matches one char in a **range** | `letter[a-e].rpyc` → `lettera.rpyc` |
|
|
81
|
+
| `[!abc]` | Matches one char **NOT** in the set | `img[!0-9].png` → `imgA.png`, but NOT `img1.png` |
|
|
82
|
+
|
|
83
|
+
## Tips:
|
|
84
|
+
1. **Extensions:** Always start with `*.` for extensions.
|
|
85
|
+
✅ `-m "*.jpg"`
|
|
86
|
+
❌ `-m ".jpg"` (looks for a file literally named `.jpg`)
|
|
87
|
+
2. **Paths vs Names:** Masks work on both full paths and filenames.
|
|
88
|
+
- `-m "images/*"` finds everything inside the `images/` folder.
|
|
89
|
+
- `-m "bg_*"` finds any file starting with `bg_`, regardless of its folder.
|
|
90
|
+
3. **OR Logic:** Multiple `-m` flags are combined with OR.
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## Disclaimer
|
|
95
|
+
|
|
96
|
+
This program is intended for people who have the legal rights or the consent of the target app authors to access or decompress the archive files. Any illegal or otherwise unintended usage of this software is discouraged and unsupported.
|
|
97
|
+
|
|
98
|
+
## Credits
|
|
99
|
+
|
|
100
|
+
This software was developed with orientation on Ren'Py's source code for working with RPA files. Credits for the development of the Ren'Py archive format belong to the contributors of the [Ren'Py project](https://github.com/renpy/renpy).
|
|
101
|
+
|
|
102
|
+
## Support
|
|
103
|
+
|
|
104
|
+
If this tool saved you time, consider supporting the developer:
|
|
105
|
+
|
|
106
|
+
**ERC-20** ```0x8BA3456DBf94891881204ECB7a0f2fbdb6228D8A```
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
**SOL** ```H93HCZ1KqvnmAgDh9Enyi2xgUnXXXA5yb7uDxeshQJq```
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
rpx_kit/__init__.py,sha256=HfjVOrpTnmZ-xVFCYSVmX50EXaBQeJteUHG-PD6iQs8,22
|
|
2
|
+
rpx_kit/cli.py,sha256=Pd9DUmn7D4Ycw2Z8LdaE8_iiZLU4wWMeMOHMS-EO-tI,3453
|
|
3
|
+
rpx_kit/core.py,sha256=2NYCrYxram_pXKvoGV6rLCO81ynNrsd0uld88acgCWs,2015
|
|
4
|
+
rpx_kit-0.2.3.dist-info/METADATA,sha256=PtHfwRocc_jnLeWV9wUFY7uVl-hrcuPPvdZ4hjbY6nY,4094
|
|
5
|
+
rpx_kit-0.2.3.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
6
|
+
rpx_kit-0.2.3.dist-info/entry_points.txt,sha256=9qyu64DJKd1nlwS0fACUQQLShTgBMr9hBZniCVQdUrw,45
|
|
7
|
+
rpx_kit-0.2.3.dist-info/licenses/LICENSE,sha256=CpUSTmFR23BcNB48sJChQKKL0cZRbfDcFkExIkddkzI,1068
|
|
8
|
+
rpx_kit-0.2.3.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Padorublad3
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|