Skip to content

Commit

Permalink
Merge pull request #1 from tomchapin/executable-version
Browse files Browse the repository at this point in the history
Executable version
  • Loading branch information
tomchapin authored Jul 12, 2019
2 parents 4ec6c94 + 24f9948 commit 115f4b6
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 54 deletions.
32 changes: 24 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,44 @@
# Undertale PC/Switch Save File Converter V2.0
# Undertale PC/Switch Save File Converter V2.1
Inspired by JonyLuke's Undertale Save Converter (https://github.com/jonyluke/Undertale-save-converter).
This version is a complete re-write, and features full bi-directional conversion functionality.

[Project page on the GBATemp Forum](https://gbatemp.net/threads/undertale-save-game-converter-v2-with-full-bi-directional-pc-switch-conversion-ability.542897/)

## Requirements
- Python3 (https://www.python.org/downloads/)

## Requirements
- Undertale
- A Modded Nintendo Switch
- Python3.4 (https://www.python.org/downloads/) - Optional
(Note: This is only required if you want to compile the converter.exe file yourself, or if you want to run converter.py directly)


## Installation and Usage
1. Download the latest release from https://github.com/tomchapin/undertale-save-converter/releases
2. Save it to a folder on your local computer.
3. Copy your game save files to the same folder.
4. Make sure you have Python3 installed


### Converting from PC to Switch
1. Make sure you have copied your game's file0, file9, and undertale.ini files into the folder with the converter.py file.
1. Make sure you have copied your game's file0, file9, and undertale.ini files into the folder with the undertale_save_converter.exe file.
(These files are typically located in your system's %LocalAppData%\UNDERTALE\ folder)
2. Use your command prompt to browse to the folder, then execute `python converter.py` and select the first menu option.
2. Use your command prompt to browse to the folder, then execute `undertale_save_converter.exe` and select the first menu option.
3. Alternately (if you want to run the script via python), execute `python undertale_save_converter.py` (requires Python 3 to be installed).


### Converting from Switch to PC
1. Make sure you have the undertale.sav file copied from your Nintendo Switch placed in the folder with the converter.py file.
1. Make sure you have the undertale.sav file copied from your Nintendo Switch placed in the folder with the undertale_save_converter.exe file.
This file can be obtained from a modded switch by using tools such as Checkpoint or JKSM.
- Checkpoint: https://gbatemp.net/threads/checkpoint-a-simple-and-fast-save-manager.485591
- JKSM: https://github.com/J-D-K/JKSM
2. Use your command prompt to browse to the folder, then execute `python converter.py` and select the second menu option.
2. Use your command prompt to browse to the folder, then execute `undertale_save_converter.exe` and select the second menu option.
3. Alternately (if you want to run the script via python), execute `python undertale_save_converter.py` (requires Python 3 to be installed).


### Compiling the executable (if you don't want to download and use the supplied converter.exe file)
1. Install Python 3.4 (x86) on a Windows computer, making sure you select the option to add Python to your path.
2. Install the Py2Exe utility (`py -3.4 -m pip install py2exe`) - https://pypi.org/project/py2exe/
3. Install pywin32-221.win32-py3.4.exe from https://sourceforge.net/projects/pywin32/files/pywin32/Build%20221/
4. Check out this git repo to a folder on your local computer.
5. Browse to the folder and execute `pip install -r requirements.txt` (to install dependencies).
6. Execute `py -3.4 -m py2exe.build_exe undertale_save_converter.py` to compile the converter.py file to an .exe file.
7. Look inside the `dist` folder for your newly created `undertale_save_converter.exe` file!
62 changes: 16 additions & 46 deletions converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,23 @@
# https://github.com/tomchapin/undertale-save-converter

#############################################################################################
# Helper Methods
# Imports
#############################################################################################

import msvcrt # For getting user input on Windows (we use this on our main menu)
import subprocess # For executing a shell command (we use this to clear the screen)

def get_char():
"""
Gets a single character from user input.
Compatible with both Unix and Windows.
"""
try:
# Attempt the Windows method
import msvcrt
char = msvcrt.getch()
except ImportError:
# Fall back on the Unix method
import sys
import tty
import termios
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())
char = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return char


def file_length(file_path):
"""
Returns the number of lines in a file
"""
file_handler = open(file_path)
num_lines = sum(1 for _line in file_handler)
file_handler.close()
return num_lines

#############################################################################################
# Helper Methods
#############################################################################################

def clear_screen():
"""
Clears the terminal screen.
Compatible with both Unix and Windows.
Only compatible with Windows.
"""
import platform # For getting the operating system name
import subprocess # For executing a shell command
command = "cls" if platform.system().lower() == "windows" else "clear"
return subprocess.call(command, shell=True) == 0
return subprocess.call("cls", shell=True) == 0


#############################################################################################
Expand All @@ -60,16 +30,16 @@ def pc_file_to_switch_text(input_file):
Converts all of the PC file's lines to a single line of text meant for the Switch game save file
"""
result = ''
line_count = file_length(input_file.name)
file_contents = input_file.read()

for cnt, line in enumerate(input_file):
for cnt, line in enumerate(file_contents):
# Remove line break character from end of line
new_line = line.replace("\n", '')

# Strip spaces from the end of line
new_line = new_line.rstrip()

if cnt+1 < line_count:
if cnt+1 < len(file_contents):
# Add on line break characters (unless this is the very last line)
new_line = new_line + "\\r\\n"

Expand All @@ -83,8 +53,9 @@ def pc_undertale_ini_to_switch_text(input_file):
Converts all of the undertale.ini file's lines to a single line of text meant for the Switch game save file
"""
result = ''
file_contents = input_file.read()

for cnt, line in enumerate(input_file):
for cnt, line in enumerate(file_contents):
# Remove line break character from end of line
new_line = line.replace("\n", '')

Expand Down Expand Up @@ -119,8 +90,7 @@ def convert_from_pc_to_switch():

switch_undertale_sav.write('{ "default": "", "file9": "')
switch_undertale_sav.write(pc_file_to_switch_text(pc_file9))
switch_undertale_sav.write('"')
switch_undertale_sav.write(', "config.ini": "", "undertale.ini": "')
switch_undertale_sav.write('", "config.ini": "", "undertale.ini": "')
switch_undertale_sav.write(pc_undertale_ini_to_switch_text(pc_undertale_ini))
switch_undertale_sav.write('", "file0": "')
switch_undertale_sav.write(pc_file_to_switch_text(pc_file0))
Expand Down Expand Up @@ -165,6 +135,7 @@ def file0_content_from_switch_save():

def switch_file_text_to_pc_file_lines(extracted_text):
result = ''

# Convert all the line endings to PC line endings
lines = extracted_text.split("\\r\\n")

Expand Down Expand Up @@ -228,7 +199,7 @@ def display_menu():
print("")
print(" Press (1) or (2) to select a menu option, or press (Escape) to exit:")

user_input = get_char()
user_input = msvcrt.getch()
if user_input == b'1':
# 1 was pressed
convert_from_pc_to_switch()
Expand All @@ -245,4 +216,3 @@ def display_menu():

if __name__ == '__main__':
display_menu()

1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pyreadline
Binary file added undertale_save_converter.zip
Binary file not shown.

0 comments on commit 115f4b6

Please sign in to comment.