Skip to main content

A Python library for parsing and modifying RPF files for GTA IV.

Project description

pyrpfiv

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.

Table of Contents

Core Functions

Setup & Requirements

Documentation

Additional Information

Features

  • 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

Installation

pip install pyrpfiv

Requirements

  • Python 3.8 or higher
  • pycryptodome >= 3.19.0
  • GTA IV executable version 1.0.8.0 (other versions are not supported)
  • hashes.ini file in working directory (for filename resolution)

Basic Usage

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
)

API Reference

RPFParser Class

Initialization

parser = RPFParser(rpf_filename: str, gtaiv_exe_path: str)
  • rpf_filename: Path to the RPF file you want to work with
  • gtaiv_exe_path: Path to GTA IV executable version 1.0.8.0 (needed for AES key extraction)

File Operations

Extracting Files
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 archive
  • output_dir: Directory where the file should be extracted
Replacing Files
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 one
  • rpf_path: Path of the file to replace within the RPF archive
Listing Files
# 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}")
Exporting RPF Contents
# Export to JSON
parser.save_json("rpf_contents.json")

File Structure Requirements

hashes.ini

The library requires a hashes.ini file in the working directory for resolving file name hashes. Format:

hash_value=filename
# Example:
123456789=track_01

Error Handling

The library provides several custom exceptions for proper error handling:

  • RPFParsingError: General parsing errors
  • FileExtractionError: File extraction failures
  • FileNotFoundInRPFError: File not found in RPF archive
  • HashesFileNotFoundError: Missing hashes.ini file
  • InvalidTOCEntryError: Invalid TOC entry
  • AESKeyExtractionError: Failed to extract AES key
  • TOCDecryptionError: 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}")

Technical Details

Version Support

Currently, only GTA IV version 1.0.8.0 is supported. This is because the AES key extraction is specifically tailored for this version of the executable. Other versions of GTA IV will not work with this library.

Disclaimer

This tool is provided for educational and research purposes only. The RPF file format is proprietary to Rockstar Games. Users of this library should:

  1. Respect Rockstar Games' intellectual property rights
  2. Comply with Rockstar Games' terms of service and EULA
  3. Only use this tool with legally obtained copies of GTA IV version 1.0.8.0
  4. Not use this tool for unauthorized distribution or modification of game files

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

Special thanks to:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyrpfiv-0.1.2.tar.gz (892.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyrpfiv-0.1.2-py3-none-any.whl (904.9 kB view details)

Uploaded Python 3

File details

Details for the file pyrpfiv-0.1.2.tar.gz.

File metadata

  • Download URL: pyrpfiv-0.1.2.tar.gz
  • Upload date:
  • Size: 892.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.1

File hashes

Hashes for pyrpfiv-0.1.2.tar.gz
Algorithm Hash digest
SHA256 c634fe7163dffc8cba2a64e8dd5837941972e4689b21cb61d2bb7adb606a9ce9
MD5 657bd01b951ad7739e25107779b3cdd7
BLAKE2b-256 586b35dce74f17a86f252004ca302556430057b7c04f5307e4706f8471c1cb25

See more details on using hashes here.

File details

Details for the file pyrpfiv-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: pyrpfiv-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 904.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.1

File hashes

Hashes for pyrpfiv-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1cc6c3078bffb5593730abcf26ba767e647efdd9b276a6d8be905bc06e43e254
MD5 747c112e1b5dedd228d818c06bb08796
BLAKE2b-256 49b4b3e51c2b10fd4c62410e18b8dd8f651d7ad02b4a65c173f19e80ec3d557a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page