Metadata-Version: 2.4
Name: wiithon
Version: 0.1.0
Summary: Wii ISO reading, patching and rebuilding library
Project-URL: Homepage, https://github.com/Demorck/wiithon
Project-URL: Issues, https://github.com/Demorck/wiithon/issues
Project-URL: Documentation, https://github.com/Demorck/wiithon/tree/master/docs
Author: demorck
License-Expression: MIT
License-File: LICENSE.md
Keywords: bcsv,bnr,dol,iso,lz77,nintendo,patching,rarc,reverse-engineering,rom-hacking,u8,wii
Requires-Python: >=3.11
Requires-Dist: pycryptodome>=3.0
Requires-Dist: rich>=13.0
Requires-Dist: typer>=0.9
Provides-Extra: dev
Requires-Dist: build; extra == 'dev'
Requires-Dist: mypy>=1.11; extra == 'dev'
Requires-Dist: pytest>=8; extra == 'dev'
Requires-Dist: ruff>=0.6; extra == 'dev'
Description-Content-Type: text/markdown

# Wiithon

A Python library for reading, extracting, and rebuilding Nintendo Wii ISO files. 

## Features

* Parse and extract files from standard Wii ISOs.
* Read the Wii File System Table (FST) and reconstruct the directory tree.
* On-the-fly decryption and encryption of Wii data clusters.
* Rebuild and master new Wii ISOs from extracted or modified files.
* Hash calculation and Merkle tree generation for partition integrity. (doesn't work great atm)

## Documentation

For comprehensive guides, internal architecture details, and references, please refer to the [docs/](docs/) directory.

## Examples

For some examples, you can refer to the [examples/](examples/) directory.

## Overview

The library is divided into two main components: reading existing ISOs and building new ones.

### Reading and Extracting

To read an ISO, initialize the `WiiIsoReader` with a binary stream. You can iterate through the partitions and access the decrypted file data using the FST offsets.
(currently just copied/paste the examples in the above directory)

```python
from wiithon.disc.WiiIsoReader import WiiIsoReader

# Opening the ISO
with WiiIsoReader("your_iso_file.iso") as reader:
    print(f"Game: {reader.disc_header.game_title}")

    data = reader.get_data_partition()
    partition = reader.open_partition(data)

    for path in partition.list_files():
        print(path)

    print(f"Number of files: {len(partition.list_files())}")
```

### Building
To build an ISO, you can use some interfaces. Each interface has their specificities like copying an ISO, patching an ISO or building from a folder from your explorer.
Currently, only the copy one exists.

```python
from wiithon.builder.CopyBuilder import CopyBuilder
from wiithon.disc.WiiIsoReader import WiiIsoReader
from wiithon.builder.WiiDiscBuilder import WiiDiscBuilder

SOURCE_PATH = "your_iso_file.iso"
DEST_PATH = "output_iso.iso"

print(f"Source : {SOURCE_PATH}")
print(f"Dest   : {DEST_PATH}")

# Open the original ISO
with WiiIsoReader(SOURCE_PATH) as reader:
    print(f"Game   : {reader.disc_header.game_title.strip()}")
    print(f"ID     : {reader.disc_header.game_id.decode()}")

    # The main builder
    builder = WiiDiscBuilder(reader.disc_header, reader.region)

    with open(DEST_PATH, 'w+b') as dest:
        # For each partition from the original ISO
        for entry in reader.partitions:
            # Copying and build into the new one
            copy_builder = CopyBuilder(reader, entry, None)
            builder.add_partition(dest, copy_builder, None)

        # To write the header and partitions datas 
        builder.finish(dest)
```

## TODO
### Done
- [x] Fixing the H3 table (Dolphin says that is not correct :( ) 
- [x] Fixing a thing that dolphin says: some block are incorrect but unused
- [x] Adding more WiiPartitionInterface from dir
- [x] Some docs about building and so on
- [x] Adding some tools like Yaz0, RARC
- [x] Writing asm easily
- [x] Patching DOL
- [x] Adding, modifying, removing files
- [x] Wrapper for modifying rarc file
---
### Next to do
- [ ] Searching empty addresses in dol to add instructions and adding text/data sections
- [ ] Refactor/adding constants to avoid magic numbers
- [ ] Comment all functions (and inside of it)
- [ ] BCSV editor
- [ ] BMD - BDL editor
---
### Next after next (not ordered)
- [ ] Patcher !! (will be available with tools maybe ?)
- [ ] Some refactorization (like big break big function into smaller ones)
- [ ] Add more unit tests (and change some)
- [ ] Improve exception handling for invalid or corrupted ISO headers
- [ ] Add a CLI for standard extraction and building
- [ ] Adding everything we need to proper have a PyPi page