A Python library for parsing and modifying RPF (Resource Package Format) files, specifically designed for Grand Theft Auto IV. This library provides simple functionality to read, extract, and modify files within RPF archives while handling encryption and file name hashing.
- File Extraction - Extract files from RPF archives
- File Replacement - Replace files in RPF archives
- File Listing - List all files in RPF archives
- JSON Export - Export RPF contents to JSON
- Parse RPF3 file format used in GTA IV
- Extract files from RPF archives
- Add/Replace files in RPF archives while preserving hash structure
- Automatic handling of encrypted TOC (Table of Contents)
- Support for file name hash resolution using hashes.ini
- JSON export of RPF contents
- Detailed logging of operations
pip install pyrpfiv
- Python 3.8 or higher
- pycryptodome >= 3.19.0
- GTA IV executable version 1.0.8.0, 1.2.0.43, or 1.2.0.59 (other versions are not supported)
- hashes.ini file in working directory (for filename resolution)
from pyrpfiv import RPFParser
# Initialize parser with RPF file and GTA IV executable path
parser = RPFParser(
rpf_filename="path/to/your.rpf",
gtaiv_exe_path="path/to/gtaiv.exe" # Must be version 1.0.8.0, 1.2.0.43, or 1.2.0.59
)
parser = RPFParser(rpf_filename: str, gtaiv_exe_path: str)
rpf_filename
: Path to the RPF file you want to work withgtaiv_exe_path
: Path to GTA IV executable (versions 1.0.8.0, 1.2.0.43, or 1.2.0.59 supported for AES key extraction)
parser.extract_file(
file_path="RADIO_VLADIVOSTOK/track_01", # Note: RPF files don't use extensions
output_dir="output/directory"
)
file_path
: Path of the file within the RPF archiveoutput_dir
: Directory where the file should be extracted
parser.add_file(
source_file="path/to/new/audio",
rpf_path="RADIO_VLADIVOSTOK/track_01" # Note: RPF files don't use extensions
)
source_file
: Path to the new file that will replace the existing onerpf_path
: Path of the file to replace within the RPF archive
# Access all files in the RPF
for entry in parser.paths:
print(f"File: {entry['path']}")
print(f"Size: {entry['size']} bytes")
print(f"Offset: 0x{entry['offset']:X}")
# Export to JSON
parser.save_json("rpf_contents.json")
The library requires a hashes.ini
file in the working directory for resolving file name hashes. Format:
hash_value=filename
# Example:
123456789=track_01
The library provides several custom exceptions for proper error handling:
RPFParsingError
: General parsing errorsFileExtractionError
: File extraction failuresFileNotFoundInRPFError
: File not found in RPF archiveHashesFileNotFoundError
: Missing hashes.ini fileInvalidTOCEntryError
: Invalid TOC entryAESKeyExtractionError
: Failed to extract AES keyTOCDecryptionError
: Failed to decrypt TOC
Example error handling:
from pyrpfiv import RPFParser, FileNotFoundInRPFError
try:
parser.extract_file("nonexistent/file", "output")
except FileNotFoundInRPFError as e:
print(f"Error: {e}")
Currently, GTA IV versions 1.0.8.0, 1.2.0.43, and 1.2.0.59 are supported. The AES key extraction is specifically tailored for these versions of the executable. Other versions of GTA IV will not work with this library.
This tool is provided for educational and research purposes only. The RPF file format is proprietary to Rockstar Games. Users of this library should:
- Respect Rockstar Games' intellectual property rights
- Comply with Rockstar Games' terms of service and EULA
- Only use this tool with legally obtained copies of GTA IV versions 1.0.8.0, 1.2.0.43, or 1.2.0.59
- Not use this tool for unauthorized distribution or modification of game files
This project is licensed under the MIT License - see the LICENSE file for details.
Special thanks to:
- ahmed605's SparkIV for providing valuable reference for RPF file format handling
- dexyfex's CodeWalker for providing additional technical insights into the file format