-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
72 lines (61 loc) · 3.33 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
"""
Main file for Sly String Toolkit
"""
import os
import argparse
import time
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
from generator import Generator
DEBUG_FILE_OUTPUT = False
def main():
"""
Main function, parses command line arguments and calls the pnach generator
"""
# Parse command line arguments
parser = argparse.ArgumentParser(description='Generate PNACH file from CSV.')
parser.add_argument('input_file', type=str, help='input CSV file name (default is strings.csv)', default="strings.csv")
parser.add_argument('-o', '--output-dir', type=str, help='output directory (default is ./out/)', default="./out/")
parser.add_argument('-r', '--region', type=str, help='the region of the game, support ntsc and pal (default is ntsc)', default="ntsc")
parser.add_argument('-c', '--code-address', type=str, help='set the address where the pnach will inject the asm code')
parser.add_argument('-s', '--strings-address', type=str, help='set the address where the pnach will inject the custom strings')
parser.add_argument('-n', '--mod-name', type=str, help='name of the mod (default is same as input file)')
parser.add_argument('-a', '--author', type=str, help='name of the author (default is Sly String Toolkit)', default="Sly String Toolkit")
parser.add_argument('-d', '--dialect', type=str, help='the language of the strings file')
parser.add_argument('-e', '--csv_encoding', type=str, help='the encoding of the CSV file (default is utf-8)', default="utf-8")
parser.add_argument('-v', '--verbose', action='store_true', help='show verbose output')
parser.add_argument('-l', '--live-edit', action='store_true', help='enable live editing of strings csv file')
args = parser.parse_args()
# Make sure the input file exists
if not os.path.exists(args.input_file):
print("Usage: python main.py [input_file] [-o output_dir] [-n mod_name]")
return
# Make sure input file is a complete path
if not os.path.isabs(args.input_file):
args.input_file = os.path.abspath(args.input_file)
# Set verbose and debug flags on generator
Generator.set_verbose(args.verbose)
Generator.set_debug(DEBUG_FILE_OUTPUT)
# Create the generator and generate the pnach
generator = Generator(args.region, args.dialect, args.strings_address, args.code_address)
# Check if live-edit flag is set
if args.live_edit:
print("Live editing enabled, make changes to the strings csv file and the pnach will be updated automatically.")
# Create the observer and schedule the event handler
observer = Observer()
event_handler = FileSystemEventHandler()
event_handler.on_modified = lambda event: generator.generate_pnach_file(args.input_file, args.output_dir, args.mod_name, args.author, args.csv_encoding)
observer.schedule(event_handler, path=os.path.dirname(args.input_file), recursive=False)
# Start the observer and wait for keyboard interrupt
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
# Stop the observer
observer.join()
else:
generator.generate_pnach_file(args.input_file, args.output_dir, args.mod_name, args.author)
if __name__ == "__main__":
main()