Metadata-Version: 2.1
Name: es3-modifier
Version: 0.1.0
Summary: A package to decrypt, edit and encrypt EasySave files used in Unity games
Home-page: https://github.com/crtdll/es3-modifier
Author: crtdll
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pycryptodome

# es3-modifier

`es3-modifier` is a Python package designed for handling stat files generated by Unity's [Easy Save](https://assetstore.unity.com/packages/tools/utilities/easy-save-the-complete-save-data-serializer-system-768) tool. With it, you can seamlessly open, modify, and save new stats. This project was created for use in [es3-editor](https://github.com/crtdll/es3-editor)

## Installation
To get started, you can easily install the package using pip:
```bash
pip install es3-modifier
```

## Usage
Below is a practical demonstration of how to use this package. In this instance, we'll be working with the `Phasmophobia` game save file, extracting key details, and adjusting specific player stats:

```py
import os, re, json
from es3_modifier import ES3

def format_inventory_name(name):
  """Format the inventory name for better readability."""
  name = re.sub(r'(?<=[a-z])([A-Z])', r' \1', name)
  name = re.sub(r'(?<=[A-Z])([A-Z][a-z])', r' \1', name)
  return name.replace('Inventory', '').rstrip()

# Define the path to the Phasmophobia save file
phasmophobia_path = f'{os.environ["USERPROFILE"]}\\AppData\\LocalLow\\Kinetic Games\\Phasmophobia\\SaveFile.txt'

# Initialize ES3 with the Phasmophobia save data
with open(phasmophobia_path, 'rb') as file:
  es3 = ES3(file.read(), 't36gref9u84y7f43g')

try:
  # Load and decrypt the save data
  decrypted = es3.load()

  # Display player stats
  print(f'Money: ${decrypted["PlayersMoney"]["value"]:,}')
  print(f'Legacy Level: {decrypted["Level"]["value"]}')
  print(f'Level: {decrypted["NewLevel"]["value"]}')
  print(f'Prestige: {decrypted["PrestigeIndex"]["value"]}')

  # Display inventory
  print('\n== Inventory ==')
  for key, value in decrypted.items():
    if 'Inventory' not in key:
      continue
    formatted_name = format_inventory_name(key)
    amount = value['value']
    print(f'{formatted_name}: {amount}')

  # Modify save data values
  decrypted['PlayersMoney']['value'] = 99999
  decrypted['NewLevel']['value'] = 123

  # Save the modified data
  with open('new.txt', 'wb') as out_file:
    out_file.write(es3.save(json.dumps(decrypted)))

except Exception as e:
  print(e)
```

**Remember to always create backups before editing your save files!**

## Prerequisites
This package uses `pycryptodome` for AES, it will automatically be installed. 
