Пример #1
0
def _store_asset(gid, filename, cached_file, packager):
    with cached_file.open(filename) as wad_file:
        wad_data = wad_file.read()

    if filename.lower().endswith('.pk3'):
        # convert .pk3 to .wad
        wad_data = pk3_to_wad(wad_data)
        wad_filename = filename[:-4] + '.wad'
    else:
        wad_filename = filename

    wad = doomwad.WadFile(wad_data)
    wad.filename = wad_filename

    if not wad.find('DECORATE'):
        print('Warning: No DECORATE lump found in file {0}, '
              'skipping...'.format(filename))
        return

    patching.apply_patch(gid, wad)

    wad_data = io.BytesIO()
    wad.writeto(wad_data)

    if packager:
        wad_filename = _unique_wad_filename(wad_filename)
        packager.writestr(wad_filename, wad_data.getvalue())
Пример #2
0
def _store_lump(full_path, data_path, packager):
    relative = full_path[len(data_path):]

    optimize = relative.lower().endswith('.txt')
    filemode = 'r' if optimize else 'rb'

    print('Processing {}...'.format(relative))

    with open(full_path, filemode) as f:
        content = f.read()

    if optimize:
        content = patching.optimize_text(content)
    elif relative.endswith('.wad'):
        wad = doomwad.WadFile(content)
        wad.filename = relative

        if wad.find('DECORATE'):
            patching.apply_patch(-1, wad)

        wad_data = io.BytesIO()
        wad.writeto(wad_data)

        content = wad_data.getvalue()

    packager.writestr(relative, content)
Пример #3
0
def _process_wad(filename):
    import udmf
    import doomwad
    import os.path

    print('Processing file %s...' % filename)

    fin = open(filename, 'rb')
    wad = doomwad.WadFile(fin)

    for lump in wad:
        namespace = lump.namespace

        if 'TEXTMAP' != lump.name:
            continue

        print('Processing map %s...' % namespace)
        udmfmap = udmf.load(lump.data)

        for vertex in udmfmap.vertices:
            vertex['x'] = round(vertex['x'])
            vertex['y'] = round(vertex['y'])

        lump.data = udmfmap.astext()

    split_filename = os.path.splitext(filename)
    output_filename = split_filename[0] + '.iv' + split_filename[1]
    fout = open(output_filename, 'wb')
    wad.writeto(fout)
Пример #4
0
def dump_names(filename):
    wad_file = open(filename, 'rb')
    wad = doomwad.WadFile(wad_file)

    shortname = os.path.basename(filename).lower()
    shortname = shortname.split('.', 1)[0]

    print('lumps_{0} = ('.format(shortname))

    for namespace in wad.namespaces():
        if not skip_namespace(namespace):
            if len(namespace) > 0:
                print('# {0}'.format(namespace))

            lumps = wad.uniquenamespacelumps(namespace)
            lumps.sort(key=lambda lump: lump.name)

            for lump in lumps:
                if not lump.marker:
                    print("'{0}',".format(lump.name))

    print(')\n\nsprites_{0} = ('.format(shortname))

    for sprite in wad.spritenames():
        print("'{0}',".format(sprite))

    print(')\n')

    wad_file.close()
Пример #5
0
def main():
    opts, args = options.parse_args()
    if not args:
        options.print_help()
        return

    if opts.wad:
        f = open(opts.wad, 'rb')
        wad = doomwad.WadFile(f)
        f.close()

        dat = wad[args[0]].data
    else:
        dat = open(args[0], 'rb').read()

    acsf = acsutil.Behavior(dat)

    comment = ''
    if opts.comment:
        comment = '// '

    if opts.output:
        output = open(opts.output, 'w')
    else:
        output = sys.stdout

    if opts.strings:
        print >> output, '%sStrings:' % comment
        for i, s in enumerate(acsf.strings):
            print >> output, '%s  %3d: %r' % (comment, i, s)
        print >> output

    if opts.decompile:
        parsers = []
        for m in acsf.markers:
            if m.executable:
                if opts.goto:
                    p = GotoParser(m, acsf)
                elif isinstance(m, acsutil.Script):
                    p = SwitchParserScript(m, acsf)
                else:
                    p = SwitchParserFunction(m, acsf)
                parsers.append(p)

        print >> output, '#include "zcommon.acs"'
        print >> output
        for l in declare_vars(getvars(acsf, 'global'), 'global'):
            print >> output,  l

        for l in declare_vars(getvars(acsf, 'world'), 'world'):
            print >> output, l

        for l in declare_mapvars(acsf, getvars(acsf, 'map')):
            print >> output, l
        print >> output

        for p in parsers:
            for l in p.gen_code():
                print >> output, l
    else:
        if opts.vars:
            for l in declare_mapvars(acsf, getvars(acsf, 'map')):
                print >> output, l
            print >> output
        for m in acsf.markers:
            for lin in m.disassemble():
                print >> output, '%s%s' % (comment, lin)
Пример #6
0
import os
import sys

# all modules are in the lib directory
sys.path[0] = os.path.dirname(os.path.abspath(__file__)) + '/../lib'

import doomwad

if 2 != len(sys.argv):
    print('Usage: {} file.wad'.format(__file__))
    exit(1)

filename = sys.argv[1]

with open(filename, 'rb') as f:
    wad = doomwad.WadFile(f)

# find lump with palettes
lump = wad.find('PLAYPAL')
if not lump:
    print('Error: No palette found in {}'.format(filename))
    exit(1)

PALETTE_COLORS = 256
PALETTE_CHANNELS = 3
PALETTE_BYTES = PALETTE_COLORS * PALETTE_CHANNELS

if len(lump.data) < PALETTE_BYTES:
    print('Error: Invalid palette found in {}'.format(filename))
    exit(1)
def read_wad(zip_file, filename):
    wad_file = zip_file.open(filename)
    wad_data = wad_file.read()
    wad_file.close()

    return doomwad.WadFile(wad_data)
zip_file = zipfile.ZipFile(zip_filename)

ammo_actors_wads = {}
item_actors_wads = {}

for zipped_filename in zip_file.namelist():
    if not zipped_filename.lower().endswith('.wad'):
        continue

    # Scan WAD

    wad_file = zip_file.open(zipped_filename)
    wad_data = wad_file.read()
    wad_file.close()

    wad = doomwad.WadFile(wad_data)

    for lump in wad:
        if 'DECORATE' == lump.name:
            find_derived_actors(ammo_actors_wads, zipped_filename,
                                lump.data, 'Ammo')
            find_derived_actors(item_actors_wads, zipped_filename,
                                lump.data, 'CustomInventory')
            break

zip_file.close()

# Print names collisions

print('// Actors derived from Ammo:')
print_result(ammo_actors_wads)
Пример #9
0
def pk3_to_wad(pk3_data):
    """
    Return Doom WAD file binary content converted from .pk3 ZIP file
    in the same form (bytes as a string or string-like object)
    NOTE: Namespaces support is limited to sprites only
    """

    mem_file = io.BytesIO()
    mem_file.write(pk3_data)
    mem_file.seek(0)

    zip_file = zipfile.ZipFile(mem_file)

    directory = ''
    namespace = ''

    decorate, zip_infos = _process_decorate(zip_file)

    wad = doomwad.WadFile()
    _add_lump(wad, 'DECORATE', '', decorate)

    zip_infos = sorted(zip_infos, key=lambda i: i.filename.lower())
    sprite_namespace = 'S_START'

    for info in zip_infos:
        filename = info.filename.lower()

        if info.external_attr & 0x10:
            directory = filename
            namespace = ''

            if 'sprites/' == directory.lower():
                # add opening marker
                namespace = sprite_namespace
                _add_lump(wad, namespace, namespace)

            continue

        if not filename.startswith(directory):
            if namespace == sprite_namespace:
                # add closing marker
                _add_lump(wad, 'S_END')

            directory = ''
            namespace = ''

        lumpname = filename.upper()[len(directory):]
        if '.' in lumpname:
            lumpname = lumpname[:lumpname.rfind('.')]

        data = zip_file.open(info.filename).read()
        _add_lump(wad, lumpname, namespace, data)

    if namespace == sprite_namespace:
        # add closing marker, if file from sprites directory was the last one
        _add_lump(wad, 'S_END')

    wad_file = io.BytesIO()
    wad.writeto(wad_file)

    return wad_file.getvalue()