forked from OldGamesLab/Harold
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parseElevatorTable.py
97 lines (76 loc) · 2.69 KB
/
parseElevatorTable.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
"""
Copyright 2014-2015 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.
"""
# Parser for the elevator tables from the English Fallout 2 v1.02d .exe file
import sys, os, struct, json
NUM_ELEVATORS = 24 # there are 24 total elevators
NUM_BUTTONS = 4 # max number of buttons
# for Fallout 2 English v1.02d
GRPH_ID = 0x0002ED50 # General image stuff
INTOTAL = 0x0002ED5C # Specific image stuff for each type
BTNCOUNT = 0x0002EE1C # Number of buttons for each type
INFO = 0x0002EE7C # Information like coordinates for each type
def read32(f):
return struct.unpack("<l", f.read(4))[0]
def parseElevators(f, verbose=False):
out = {}
# generic images
f.seek(GRPH_ID)
out['buttonUp'] = read32(f)
out['buttonDown'] = read32(f)
out['positioner'] = read32(f)
elevators = [{} for _ in range(NUM_ELEVATORS)]
out['elevators'] = elevators
# types/labels
f.seek(INTOTAL)
for i in range(NUM_ELEVATORS):
elevators[i]['type'] = read32(f)
elevators[i]['labels'] = read32(f)
# button counts
f.seek(BTNCOUNT)
for i in range(NUM_ELEVATORS):
elevators[i]['buttonCount'] = read32(f)
# coordinates etc
f.seek(INFO)
for i in range(NUM_ELEVATORS):
btnCount = elevators[i]['buttonCount']
elevators[i]['buttons'] = [{} for _ in range(btnCount)]
for btn in range(NUM_BUTTONS):
if btn > btnCount-1:
# ignore unused buttons
read32(f); read32(f); read32(f)
else:
elevators[i]['buttons'][btn]['mapID'] = read32(f)
elevators[i]['buttons'][btn]['level'] = read32(f)
elevators[i]['buttons'][btn]['tileNum'] = read32(f)
if verbose:
for i in range(NUM_ELEVATORS):
print(f"elevator{i}")
print(f" type: {elevators[i]['type']}")
if elevators[i]['labels'] != -1:
print(f" labels: {elevators[i]['labels']}")
print(f" num buttons: {elevators[i]['buttonCount']}")
print(" buttons:")
for btn in elevators[i]['buttons']:
print(f" -> map {btn['mapID']}, level {btn['level']}, tile {btn['tileNum']}")
return out
def main():
if len(sys.argv) < 2:
print(f"USAGE: {sys.argv[0]} fallout2.exe")
sys.exit(1)
with open(sys.argv[1], "rb") as f:
elevators = parseElevators(f, verbose=True)
with open("lut/elevators.json", "w") as g:
json.dump(elevators, g)
print("done")
if __name__ == '__main__':
main()