Skip to content

Commit

Permalink
fix error on trainer_name being None; edit README.md for release
Browse files Browse the repository at this point in the history
  • Loading branch information
abeRC committed Apr 17, 2023
1 parent afb2590 commit 11f173e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 19 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ bla.py
*.sav
*.SAV
*.nds
*.NDS
*.NDS
*.zip
windows/
dist-linux/
17 changes: 9 additions & 8 deletions PkGender.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def parse_arguments():
'in gen IV Pokémon games (Diamond, Pearl, Platinum, HeartGold, SoulSilver).',
epilog=version_string,
formatter_class=argparse.RawTextHelpFormatter) # print help for name in a prettier way
parser.add_argument('savepath', help="path to save file") # positional argument
parser.add_argument('savefile', help="path to save file") # positional argument

parser.add_argument('--name', help="change trainer's name to specified string\n (limit of 7 characters)") # takes a value
parser.add_argument('--gender', action='store_true', help="swap trainer's gender") # on/off flag
Expand All @@ -100,13 +100,14 @@ def verify_soundness (save_path : str, to_change : ChangeList):
if not save_path.lower().endswith(".sav"):
logging.warn("Save file does not have the .sav extension.")

# verify if name is <= 7 characters and alphanumeric
# if not None, verify if name is <= 7 characters and alphanumeric
trainer_name = to_change.name
if len(trainer_name) >= 8:
raise ValueError("Trainer name must have 7 or less characters.")
alpha_num = set(string.digits+string.ascii_letters)
if set(trainer_name).difference(alpha_num): # if trainer_name has characters not in alpha_num
raise ValueError("Trainer name may only contain alphanumeric characters currently.")
if trainer_name:
if len(trainer_name) >= 8:
raise ValueError("Trainer name must have 7 or less characters.")
alpha_num = set(string.digits+string.ascii_letters)
if set(trainer_name).difference(alpha_num): # if trainer_name has characters not in alpha_num
raise ValueError("Trainer name may only contain alphanumeric characters currently.")


def read_save (save_path : str) -> bytes:
Expand Down Expand Up @@ -270,7 +271,7 @@ def edit_save (data_all : bytes, target_game : TargetGame, to_change : ChangeLis
def main ():
# parse arguments
args = parse_arguments()
save_path = args.savepath
save_path = args.savefile
to_change = ChangeList(gender=args.gender, name=args.name)
verify_soundness(save_path, to_change)

Expand Down
38 changes: 28 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,45 @@ A Python script to change trainer data (name, gender, etc.) in gen IV Pokémon g

* **USE AT YOUR OWN RISK!**

* Python 3.6+ required
* Note: NO$GBA prepends .sav files with a header, making them a slightly different format. Please convert to regular .sav files before using this tool.

### Setup

* It is recommended to run this script inside a [conda environment](https://docs.conda.io/projects/conda/en/latest/user-guide/install/index.html) with the [fastcrc module](https://fastcrc.readthedocs.io/en/latest/) installed (through pip).
* To use the [provided binaries](https://github.com/abeRC/PkGender/releases/), unzip the archive and run the executable normally according to usage instructions.

* To run this script using the Python interpreter, Python 3.6+ is required.

* It is recommended to run this script inside a [conda environment](https://docs.conda.io/projects/conda/en/latest/user-guide/install/index.html) with the [fastcrc module](https://fastcrc.readthedocs.io/en/latest/) installed (through pip).

* You could also install fastcrc through your system pip (pip3 on Linux).

* Note: NO$GBA prepends .sav files with a header, making them a slightly different format. Please convert to regular .sav files before using this tool.

### Usage

```
PkGender.py [--name NAME] [--gender] [--verify-only] [--help] [--debug] [--version] savepath
```
* Linux (from a terminal prompt)

```
./PkGender [--name NAME] [--gender] [--verify-only] [--help] [--debug] [--version] savefile
```

* Windows (from a powershell or cmd prompt)

NOTE: This may or may not work since it was compiled in a weird way (i.e., using wine instead of a Windows system). On my tests, it did work, though, so it should be ok. :)

```
.\PkGender [--name NAME] [--gender] [--verify-only] [--help] [--debug] [--version] savefile
```

* Python interpreter (see Setup for dependencies)

```
python PkGender.py [--name NAME] [--gender] [--verify-only] [--help] [--debug] [--version] savefile
```

* Positional arguments:

| Argument | Description |
| -------- |:-----------------:|
| savepath | path to save file |
| savefile | Path to save file |

* Optional arguments:

Expand All @@ -41,8 +61,6 @@ PkGender.py [--name NAME] [--gender] [--verify-only] [--help] [--debug] [--versi

* Support to change trainer id, secret id, money, badges, country of origin / language

* Executable binaries

* Support for additional generations of Pokémon games

* Visual interface

0 comments on commit 11f173e

Please sign in to comment.