This repository has been archived by the owner on Nov 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
setup.py
217 lines (164 loc) · 6.17 KB
/
setup.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
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
"""
Copyright 2015-2017 darkf
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
# Setup script to import Fallout 2 data for DarkFO
from __future__ import print_function
import sys, os, glob, json, traceback
def error(msg):
print("ERROR:", msg)
raw_input("")
sys.exit(1)
def warn(msg):
print("WARNING:", msg)
def info(msg):
print(msg)
# Check for numpy and pillow (required)
info("Checking for necessary Python modules...")
try: import numpy
except ImportError:
error("NumPy not found. Please install it from http://www.numpy.org or http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy . Make sure the version matches your installed version of Python (%d.%d)." % (sys.version_info.major, sys.version_info.minor))
try: from PIL import Image
except ImportError:
error("Pillow not found. Please see https://pillow.readthedocs.io/en/4.0.x for installation instructions. Make sure the version matches your installed version of Python (%d.%d)." % (sys.version_info.major, sys.version_info.minor))
# import local modules
import dat2
import parseCritTable
import parseElevatorTable
import exportImagesPar
import exportPRO
import fomap
# global paths/flags
SRC_DIR = None
NO_EXTRACT_DAT = False
NO_EXPORT_IMAGES = False
EXE_PATH = None
def setup_check():
global EXE_PATH
# Check whether everything we need to set up is included in the given source directory
print("Checking installation directory (%s)..." % SRC_DIR)
def install_file_exists(path):
return os.path.exists(os.path.join(SRC_DIR, path))
if not os.path.exists(SRC_DIR):
error("Installation directory (%s) does not exist." % SRC_DIR)
if not (install_file_exists("master.dat") and install_file_exists("critter.dat")):
error("Installation directory does not contain master.dat or critter.dat, please ensure they exist.")
if not install_file_exists("fallout2.exe"):
warn("Installation directory does not contain fallout2.exe. Please ensure this is the right directory and the file exists. Some features may not be available without it!")
else:
EXE_PATH = os.path.join(SRC_DIR, "fallout2.exe")
return True
def parse_crit_table():
if EXE_PATH is not None:
info("Parsing critical table from fallout2.exe...")
try:
with open(EXE_PATH, "rb") as fp:
# TODO: Don't hardcode paths, and need version check!
critTables = parseCritTable.readCriticalTables(fp, 0x000fef78, 0x00106597)
json.dump(critTables, open("lut/criticalTables.json", "w"))
info("Done parsing critical table")
except Exception:
traceback.print_exc()
warn("Error occurred while parsing critical table (see traceback above).")
else:
warn("Cannot parse critical table, missing fallout2.exe")
return True
def parse_elevator_table():
if EXE_PATH is not None:
info("Parsing elevator table from fallout2.exe...")
try:
with open(EXE_PATH, "rb") as fp:
elevators = parseElevatorTable.parseElevators(fp)
json.dump(elevators, open("lut/elevators.json", "w"))
info("Done parsing elevator table")
except Exception:
traceback.print_exc()
warn("Error occurred while parsing elevator table (see traceback above).")
else:
warn("Cannot parse elevator table, missing fallout2.exe")
return True
def extract_dats():
# Create data directory
if not os.path.exists("data"):
os.mkdir("data")
def extract_dat(path):
with open(path, "rb") as f:
dat2.dumpFiles(f, "data")
if not NO_EXTRACT_DAT:
# Extract DATs
info("Extracting master.dat...")
extract_dat(os.path.join(SRC_DIR, "master.dat"))
info("Extracting critter.dat...")
extract_dat(os.path.join(SRC_DIR, "critter.dat"))
info("Done extracting DAT archives.")
return True
def export_images():
# Export FRMs/FR[0-9]s
try:
palette = exportImagesPar.readPAL(os.path.join("data", "color.pal"))
except IOError:
error("Couldn't read data/color.pal")
# Export them to art/, which will be created if it does not already exist.
info("Converting images, please wait while this runs.")
try:
exportImagesPar.convertAll(palette, "data", "art", verbose=True)
except Exception:
traceback.print_exc()
warn("Error when converting images (see traceback above). Will not finish converting images, but will continue setup.")
return False
return True
def export_pros():
# Export PROs
info("Converting prototypes (PROs), please wait while this runs.")
exportPRO.extractPROs(os.path.join("data", "proto"), "proto")
return True
# TODO: extract audio using convertAudio
def export_maps():
# Export MAPs
info("Converting map files, please wait while this runs.")
if not os.path.exists("maps"):
os.mkdir("maps")
for mapFile in glob.glob(os.path.join("data", "maps", "*.map")):
mapName = os.path.basename(mapFile).lower()
outFile = os.path.join("maps", os.path.splitext(mapName)[0] + ".json")
try:
info("Converting map %s ..." % mapFile)
fomap.exportMap("data", mapFile, outFile)
except Exception:
traceback.print_exc()
warn("Error converting map %s (see traceback above). Will continue converting the rest." % mapFile)
return True
def main():
global SRC_DIR, NO_EXTRACT_DAT, NO_EXPORT_IMAGES
if len(sys.argv) < 2:
print("USAGE:", sys.argv[0], "FALLOUT2_INSTALL_DIR [--no-extract-dat] [--no-export-images]")
return
NO_EXTRACT_DAT = "--no-extract-dat" in sys.argv
if NO_EXTRACT_DAT:
sys.argv.remove("--no-extract-dat")
NO_EXPORT_IMAGES = "--no-export-images" in sys.argv
if NO_EXPORT_IMAGES:
sys.argv.remove("--no-export-images")
SRC_DIR = sys.argv[1]
setup_check()
parse_crit_table()
parse_elevator_table()
extract_dats()
if not NO_EXPORT_IMAGES:
export_images()
export_pros()
export_maps()
info("")
info("Setup complete. Please review the messages above, looking for any warnings.")
info("Please run tsc after this to compile the source files.")
raw_input("")
if __name__ == "__main__":
main()