forked from mkw-sp/mkw-sp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
version.py
executable file
·44 lines (34 loc) · 1.01 KB
/
version.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
#!/usr/bin/env python3
from argparse import ArgumentParser
import struct
import sys
MAJOR = 0
MINOR = 1
PATCH = 12
def write_u16(out_file, val):
out_file.write(struct.pack('>H', val))
def write_type(out_file, val):
val = {
'debug': 0,
'test': 1,
'release': 2,
}[val]
write_u16(out_file, val)
def write_string(out_file, val):
out_file.write(val.encode('ascii') + b'\0')
parser = ArgumentParser()
parser.add_argument('type', choices = ['debug', 'test', 'release'])
parser.add_argument('out_path')
args = parser.parse_args()
with open(args.out_path, 'wb') as out_file:
write_type(out_file, args.type)
write_u16(out_file, MAJOR)
write_u16(out_file, MINOR)
write_u16(out_file, PATCH)
out_file.write(b'\0' * 0x18) # Reserved bytes
string = f'{MAJOR}.{MINOR}.{PATCH} ({args.type[:1].upper() + args.type[1:]})'
write_string(out_file, string)
size = out_file.tell()
if size > 0x60:
sys.exit('Too long')
out_file.write(b'\0' * (0x60 - size))