forked from cebix/ff7tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworldinfo
More file actions
executable file
·123 lines (95 loc) · 3.42 KB
/
Copy pathworldinfo
File metadata and controls
executable file
·123 lines (95 loc) · 3.42 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/env python3
#
# WorldInfo - Extract script code of Final Fantasy world map files
#
# Copyright (C) Christian Bauer <www.cebix.net>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
__version__ = "1.4"
import sys
import os
import shutil
import ff7
# Print usage information and exit.
def usage(exitcode, error = None):
print("Usage: %s [OPTION...] <game_dir_or_image> <output_dir>" % os.path.basename(sys.argv[0]))
print(" -V, --version Display version information and exit")
print(" -?, --help Show this help message")
if error is not None:
print("\nError:", error, file=sys.stderr)
sys.exit(exitcode)
# Parse command line arguments
discPath = None
outputDir = None
for arg in sys.argv[1:]:
if arg == "--version" or arg == "-V":
print("WorldInfo", __version__)
sys.exit(0)
elif arg == "--help" or arg == "-?":
usage(0)
elif arg[0] == "-":
usage(64, "Invalid option '%s'" % arg)
else:
if discPath is None:
discPath = arg
elif outputDir is None:
outputDir = arg
else:
usage(64, "Unexpected extra argument '%s'" % arg)
if discPath is None:
usage(64, "No disc image or game data input directory specified")
if outputDir is None:
usage(64, "No output directory specified")
try:
if os.path.isfile(discPath):
discPath = ff7.cd.Image(discPath)
elif not os.path.isdir(discPath):
raise EnvironmentError("'%s' is not a directory or disc image file" % discPath)
# Check that this is a FF7 disc
version, discNumber, execFileName = ff7.checkDisc(discPath)
# Create the output directory
if os.path.isfile(outputDir):
print("Cannot create output directory '%s': Path refers to a file" % outputDir, file=sys.stderr)
sys.exit(1)
if os.path.isdir(outputDir):
answer = None
while answer not in ["y", "n"]:
answer = input("Output directory '%s' exists. Delete and overwrite it (y/n)? " % outputDir)
if answer == 'y':
shutil.rmtree(outputDir)
else:
sys.exit(0)
try:
os.makedirs(outputDir)
except OSError as e:
print("Cannot create output directory '%s': %s" % (outputDir, e.strerror), file=sys.stderr)
sys.exit(1)
# Extract all world map files
worldMaps = ["WM%X" % i for i in range(13)]
worldMaps += ["WM%XS" % i for i in range(11)]
for map in worldMaps:
print(map)
# Retrieve the map file
worldMap = ff7.world.WorldMap(ff7.retrieveFile(discPath, "WORLD", map + ".TXZ"))
# Create the output file
filePath = os.path.join(outputDir, map.lower() + ".txt")
try:
f = open(filePath, "w", encoding = "utf-8")
except IOError as e:
print("Cannot create file '%s': %s" % (filePath, e.strerror), file=sys.stderr)
sys.exit(1)
# Print a header
print("#", file=f)
print("#", map, file=f)
print("#", file=f)
print(file=f)
# Dump the script
print(ff7.world.disassemble(worldMap.getScript()), file=f)
f.close()
except Exception as e:
# Pokemon exception handler
print(e, file=sys.stderr)
sys.exit(1)