# pyz3r for Python 3.6, 3.7, and 3.8!
Pyz3r is an unofficial python abstraction library for interacting with the [alttpr.com](https://alttpr.com) API.
This allows developers to create applications that not only generate games on [alttpr.com](https://alttpr.com),
but also create the ROM as well using the patch data provided by the website.
## Installation
This module is available on PyPI. It can be installed via pip:
`pip install pyz3r`
## Compatiblity
This library has been tested on both Linux (Centos 7) and Windows on Python 3.6. Python 3.7 should also work, though it hasn't been as extensively tested. An internet connection is required so it can communicate with alttpr.com.
## Disclaimer(s)
This is an unofficial tool. Please do not submit bug reports on the official ALTTPR repository Github for issues that
are related to the use of this library!
If something is broken, please make sure it isn't related to this library before posting the bug report on the
alttp_vt_randomizer repository. Feel free to post the bug here first if you're unsure.
Using this library to patch a ROM for racing may not be permitted.
Its best to check with an official before using it for racing.
Finally, this library may break when new versions of the Link to the Past Randomizer are released. This version
was tested with v31, however it may cease to function in later releases. If it does, please submit a Github issue!
## Usage
Basic usage is fairly simple.
First you'll need to either generate a new seed or use the hash of a previous seed to get a game.
### Initiating an Item Randomizer seed
The below example will generate an item randomizer game with a list of settings:
```python
import pyz3r
async def main():
seed = await pyz3r.alttpr(
settings={
"glitches": "none",
"item_placement": "advanced",
"dungeon_items": "standard",
"accessibility": "items",
"goal": "ganon",
"crystals": {
"ganon": "random",
"tower": "4"
},
"mode": "open",
"entrances": "none",
"hints": "on",
"weapons": "randomized",
"item": {
"pool": "normal",
"functionality": "normal"
},
"tournament": True,
"spoilers": "off",
"lang":"en",
"enemizer": {
"boss_shuffle":"none",
"enemy_shuffle":"none",
"enemy_damage":"default",
"enemy_health":"default"
}
}
)
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
```
This will give you a list of item randomizer options as a dictionary:
```python
pyz3r.alttpr().settings()
```
### Loading an already generated game
If the game you want to work with has already been generated, you can load the hash like this:
```python
import pyz3r
async def main()
seed = await pyz3r.alttpr(
hash='zDvxWLLEMa'
)
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
```
### Getting the code display and URL
This will return to you a list of strings with the "code" that appears on the file select screen.
```python
code = seed.code
print("Hash: [{hash}]".format(
hash = ' | '.join(code)
))
```
Output:
`Hash: [Heart | Empty Bottle | Somaria | Ice Rod | Boots]`
You can also get the url quickly as well:
```python
url = seed.url
print("Permalink: {url}".format(
url = url
))
```
Output:
`Permalink: https://alttpr.com/h/zDvxWLLEMa`
### Accessing seed data
You can access the seed's data via the `data` variable in the alttpr class. The example below will print the dictionary that has the seed's spoiler data (if available).
```python
print(seed.data['spoiler'])
```
### Patching
This is the meat and potatoes of the library. There are two ways, the easy and advanced way.
#### Easy patching
You'll first want to read your unmodified Japan 1.0 ROM of Link to the Past. `read_rom()` will checksum the file to ensure its the correct ROM.
```python
base_rom = await pyz3r.rom.read("path/to/Zelda no Densetsu - Kamigami no Triforce (Japan).sfc")
```
`base_rom` will be an array of integers representing the bytes of the original ROM.
You'll then want to use `create_patched_game` to apply all of the patches required to randomize and customize the ROM.
```python
patched_rom = await seed.create_patched_game(
base_rom,
heartspeed='normal',
heartcolor='red',
spritename='Link', #can be any sprite listed at https://alttpr.com/sprites
music=False, # true or false, defaults true
quickswap=False,
menu_speed='normal'
)
```
Here you can customize the following:
0. `patchrom_array` - Required. This is an array of bits that have your original Japan 1.0 ROM. The `pyz3r.romfile.read()` function.
1. `heartspeed` - Optional. The low health beep speed. Acceptable values are `'off'`, `'quarter'`, `'half'`, `'double'`, or `'normal'`. Defaults is `'normal'`.
2. `heartcolor` - Optional. The color of your hearts. Acceptable values are `'red'`, `'blue'`, `'green'`, or `'yellow'`. Default is `'red'`.
3. `spritename` - Optional. The sprite to use. Acceptable values are the `name` keys in the json file at https://alttpr.com/sprites. Default is `'Link'`.
4. `music` - Optional. Whether music should play. Acceptable values are `True` and `False`. `False` allows MSU-1 music to work correctly. Default is `True`.
5. `quickswap` - Optional. Enable quickswap. Only works on non-tournament games or entrance shuffle. Acceptable values are `True` and `False`. Default is `False`.
6. `menu_speed` - Optional. This is the menu speed setting. Only works on non-tournament games. Acceptable values are `instant`, `fast`, `normal`, `slow`. Default is `normal`.
The result of `create_patched_game` is an array of integers representing the fully patched ROM.
Finally, you can write the ROM to a new file:
```python
pyz3r.romfile.write(patched_rom, "path/to/patched_rom.sfc")
```
#### Advanced patching
If you have a patched game, and just want to customize the already patched game, this library lets you do that too.
The following example will let you bring in an already patched game and let you customize the heart speed, heart color, sprite, and music.
```python
import pyz3r
from pyz3r.patch import patch
rom = pyz3r.romfile.read('path/to/rom.sfc',verify_checksum=False)
#apply the heart speed change
rom = patch.apply(
rom=rom,
patches=patch.heart_speed('half')
)
#apply the heart color change
rom = patch.apply(
rom=rom,
patches=patch.heart_color('blue')
)
#apply the sprite, retrieves a sprite from the alttpr website
rom = patch.apply(
rom=rom,
patches=patch.sprite(
spr=pyz3r.alttpr().get_sprite('Negative Link')
)
)
#apply the music
rom = patch.apply(
rom=rom,
patches=patch.music(True)
)
# apply menu speed
rom = patch.apply(
rom=patchrom_array,
patches=patch.menu_speed('normal')
)
# apply quickswap
rom = patch.apply(
rom=patchrom_array,
patches=patch.quickswap(False)
)
pyz3r.romfile.write(rom,'path/to/patched_rom.sfc')
```
### Using the customizer
The ALttPR website has a feature where a player may customize a game, including choosing starting equipment, item locations, game settings, drops and prizepack customization. This library has a feature that allows you to generate games using the settings saved on alttpr.com's customizer.
To use it, you'll want to read a `customizer-settings.json` file that was saved from alttpr.com, then use the provided function `customizer.convert2settings()` to convert the json file to