rpx-kit 0.1.0__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 +0 -0
- rpx_kit/cli.py +87 -0
- rpx_kit/core.py +64 -0
- rpx_kit-0.1.0.dist-info/METADATA +85 -0
- rpx_kit-0.1.0.dist-info/RECORD +8 -0
- rpx_kit-0.1.0.dist-info/WHEEL +4 -0
- rpx_kit-0.1.0.dist-info/entry_points.txt +2 -0
- rpx_kit-0.1.0.dist-info/licenses/LICENSE +21 -0
rpx_kit/__init__.py
ADDED
|
File without changes
|
rpx_kit/cli.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from .core import read_index,unpack_rpa,filter_index
|
|
4
|
+
from time import time
|
|
5
|
+
from sys import exit
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def validate_input_path(path:str) -> Path:
|
|
9
|
+
path_obj = Path(path)
|
|
10
|
+
if path_obj.is_file() and path_obj.suffix.lower() == ".rpa":
|
|
11
|
+
return path_obj
|
|
12
|
+
else:
|
|
13
|
+
raise argparse.ArgumentTypeError("Invalid path")
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def validate_output_path(path:str) -> Path:
|
|
17
|
+
path_obj = Path(path)
|
|
18
|
+
if path_obj.exists() and not path_obj.is_dir():
|
|
19
|
+
raise argparse.ArgumentTypeError(f"Output path exists but is not a directory: {path}")
|
|
20
|
+
else:
|
|
21
|
+
return path_obj
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
parser = argparse.ArgumentParser()
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
parser.add_argument(
|
|
28
|
+
"input_path",
|
|
29
|
+
type=validate_input_path,
|
|
30
|
+
help="Path to the RPA-3.0 archive"
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
parser.add_argument(
|
|
35
|
+
"-o",
|
|
36
|
+
"--output",
|
|
37
|
+
dest="output_path",
|
|
38
|
+
type=validate_output_path,
|
|
39
|
+
help="Output path"
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
parser.add_argument(
|
|
44
|
+
"-l",
|
|
45
|
+
"--list",
|
|
46
|
+
action="store_true",
|
|
47
|
+
help="Prints a list of files inside the archive"
|
|
48
|
+
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
parser.add_argument(
|
|
53
|
+
"-m",
|
|
54
|
+
"--mask",
|
|
55
|
+
action="append",
|
|
56
|
+
dest = "masks",
|
|
57
|
+
default=None,
|
|
58
|
+
help="Filter by mask, can be repeated: -m '*.rpyc' -m '*.png'"
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def main():
|
|
63
|
+
args = parser.parse_args()
|
|
64
|
+
with open(args.input_path,"rb") as file:
|
|
65
|
+
index = read_index(file)
|
|
66
|
+
if args.masks:
|
|
67
|
+
index = filter_index(index,args.masks)
|
|
68
|
+
if not index:
|
|
69
|
+
print("No files match the given mask")
|
|
70
|
+
exit(0)
|
|
71
|
+
if args.list:
|
|
72
|
+
for filename in index:
|
|
73
|
+
print(filename)
|
|
74
|
+
else:
|
|
75
|
+
if args.output_path is None:
|
|
76
|
+
parser.error("-o/--output is required when unpacking")
|
|
77
|
+
start_time = time()
|
|
78
|
+
args.output_path.mkdir(parents=True,exist_ok=True)
|
|
79
|
+
total = unpack_rpa(file,index,args.output_path)
|
|
80
|
+
end_time = time()
|
|
81
|
+
print("Done")
|
|
82
|
+
print(f"Total files extracted: {total}")
|
|
83
|
+
print(f"Time taken: {end_time - start_time:.2f} seconds")
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
if __name__ == "__main__":
|
|
87
|
+
main()
|
rpx_kit/core.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import pickle
|
|
2
|
+
import zlib
|
|
3
|
+
from typing import BinaryIO
|
|
4
|
+
import io
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from fnmatch import fnmatch
|
|
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,85 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: rpx-kit
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Toolkit for Ren'Py RPA 3.0 archives
|
|
5
|
+
Project-URL: Homepage, https://github.com/Padorublad3/rpx-kit
|
|
6
|
+
Project-URL: Repository, https://github.com/Padorublad3/rpx-kit
|
|
7
|
+
Author: Padorublad3
|
|
8
|
+
License: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Python: >=3.9
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
|
|
13
|
+
# RPX-KIT
|
|
14
|
+
|
|
15
|
+
## Description
|
|
16
|
+
A toolkit for extracting or viewing only RPA-3.0 archives made with Renpy
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
## Features
|
|
20
|
+
**Safe Unpickling**. Uses a custom SafeUnpickler that blocks all external imports during deserialization.
|
|
21
|
+
|
|
22
|
+
**Zero Dependencies**.
|
|
23
|
+
|
|
24
|
+
**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.
|
|
25
|
+
|
|
26
|
+
**Cross-Platform**. Works identically on Windows, Linux, and macOS. Path handling is abstracted via pathlib, so no slash-related issues.
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
## Installation
|
|
30
|
+
> [!NOTE]
|
|
31
|
+
> **Python >= 3.9** is required
|
|
32
|
+
|
|
33
|
+
Via pip
|
|
34
|
+
```bash
|
|
35
|
+
pip install git+https://github.com/Padorublad3/rpx-kit.git
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
## Usage
|
|
40
|
+
```
|
|
41
|
+
rpx-kit [-l | -o DIR] [-m PATTERN]... INPUT_PATH
|
|
42
|
+
|
|
43
|
+
Arguments:
|
|
44
|
+
INPUT_PATH Input .rpa archive file
|
|
45
|
+
|
|
46
|
+
Options:
|
|
47
|
+
-l, --list Print list of files contained in the archive
|
|
48
|
+
-o, --output Target directory for extraction (creates if missing)
|
|
49
|
+
-m, --mask Filter by fnmatch pattern (repeatable, e.g., -m "*.png")
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
## Examples
|
|
54
|
+
List all PNG and JPG files:
|
|
55
|
+
```bash
|
|
56
|
+
rpx-kit mygame/archive.rpa -m "*.png" -m "*.jpg" -l
|
|
57
|
+
```
|
|
58
|
+
Save the list to a text file:
|
|
59
|
+
```bash
|
|
60
|
+
rpx-kit mygame/archive.rpa -m "*.png" -m "*.jpg" -l > result.txt
|
|
61
|
+
```
|
|
62
|
+
Extract only PNG and JPG files to a folder:
|
|
63
|
+
```bash
|
|
64
|
+
rpx-kit mygame/archive.rpa -m "*.png" -m "*.jpg" -o destination_folder
|
|
65
|
+
```
|
|
66
|
+
## Mask Cheat Sheet
|
|
67
|
+
|
|
68
|
+
Masks use standard shell-style patterns (`fnmatch`). Remember to wrap them in quotes!
|
|
69
|
+
|
|
70
|
+
| Pattern | Meaning | Example Match |
|
|
71
|
+
| :--- | :--- | :--- |
|
|
72
|
+
| `*` | Matches **any sequence** of characters (including none) | `*.png` → `image.png`, `bg/day.png` |
|
|
73
|
+
| `?` | Matches exactly **one** character | `img?.png` → `img1.png`, but NOT `img10.png` |
|
|
74
|
+
| `[abc]` | Matches **one** char from the set | `file[123].txt` → `file1.txt`, `file2.txt` |
|
|
75
|
+
| `[a-z]` | Matches one char in a **range** | `letter[a-e].rpyc` → `lettera.rpyc` |
|
|
76
|
+
| `[!abc]` | Matches one char **NOT** in the set | `img[!0-9].png` → `imgA.png`, but NOT `img1.png` |
|
|
77
|
+
|
|
78
|
+
## Tips:
|
|
79
|
+
1. **Extensions:** Always start with `*.` for extensions.
|
|
80
|
+
✅ `-m "*.jpg"`
|
|
81
|
+
❌ `-m ".jpg"` (looks for a file literally named `.jpg`)
|
|
82
|
+
2. **Paths vs Names:** Masks work on both full paths and filenames.
|
|
83
|
+
- `-m "images/*"` finds everything inside the `images/` folder.
|
|
84
|
+
- `-m "bg_*"` finds any file starting with `bg_`, regardless of its folder.
|
|
85
|
+
3. **OR Logic:** Multiple `-m` flags are combined with OR.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
rpx_kit/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
rpx_kit/cli.py,sha256=6pCju7VMGLSBS_or_6XuKkMc8Gc_Tn-e2BJAWJfVXQ4,2155
|
|
3
|
+
rpx_kit/core.py,sha256=S8RZCHB6CtI9ttscevzsoTvuwrIsMckTg_6BMj3qnwY,2125
|
|
4
|
+
rpx_kit-0.1.0.dist-info/METADATA,sha256=UfCDJKbEvol_eCSuvnOMkDHLAImXjyaiaAVUnRHOCB8,2805
|
|
5
|
+
rpx_kit-0.1.0.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
|
|
6
|
+
rpx_kit-0.1.0.dist-info/entry_points.txt,sha256=9qyu64DJKd1nlwS0fACUQQLShTgBMr9hBZniCVQdUrw,45
|
|
7
|
+
rpx_kit-0.1.0.dist-info/licenses/LICENSE,sha256=MbRE41yUwh8Jaoy1166ERfJfdeFHF21er4msahN4_Eo,1089
|
|
8
|
+
rpx_kit-0.1.0.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.
|