File: bootstrap

package info (click to toggle)
freedoom 0.13.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 48,712 kB
  • sloc: python: 3,513; makefile: 529; xml: 188; sh: 73
file content (58 lines) | stat: -rwxr-xr-x 1,271 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env python3
# SPDX-License-Identifier: BSD-3-Clause

import sys
import struct


def read():
    try:
        return sys.stdin.buffer.read()
    except AttributeError:
        return sys.stdin.read()


def write(out):
    try:
        sys.stdout.buffer.write(out)
    except AttributeError:
        sys.stdout.write(out)


def main():
    # read PLAYPAL from stdin, write minimal doom2.wad to stdout
    if sys.stdin.isatty():
        print(
            "Usage: %s < playpal.lmp > doom2.wad" % sys.argv[0],
            file=sys.stderr,
        )
        sys.exit(1)

    # three lumps needed - see bootstrap/README.txt
    lumps = [
        (b"PLAYPAL", read()),
        (b"TEXTURE1", struct.pack("i", 0)),  # empty texture1
        (b"PNAMES", struct.pack("i8s", 1, b"")),
    ]  # single pname

    # calculate wad directory (lump offsets etc.)
    pos = 12
    waddir = []
    for name, data in lumps:
        waddir.append((pos, len(data), name))
        pos += len(data)

    # write wad header
    write(struct.pack("4sii", b"IWAD", len(waddir), pos))

    # write lump contents
    for name, data in lumps:
        write(data)

    # write wad directory
    for i in waddir:
        write(struct.pack("ii8s", *i))


if __name__ == "__main__":
    main()