Commit 0937f6a3 authored by dylan grafmyre's avatar dylan grafmyre
Browse files

mdl assert finder

parent e38e7c36
......@@ -2,41 +2,85 @@
import argparse
import os
import logging
import pyvmf
LOGGER = logging.getLogger(os.path.basename(__file__))
ARGP = argparse.ArgumentParser()
ARGP.add_argument('vmf', type=argparse.FileType())
ARGP.add_argument('--pack-used-local', action='store_true')
ARGP.add_argument('--verbose', '-v', action='store_true')
def emit_item(path):
if not os.path.exists(path):
raise RuntimeWarning('file missing: %r', path)
print(path)
print(path)
def emit_material(name, dedupe):
material_lower = 'materials/{}'.format(name.lower())
if material_lower in dedupe:
LOGGER.debug('material removd by de-dupe: %r %r', name, material_lower)
return
dedupe.add(material_lower)
LOGGER.debug('material added: %r %r', name, material_lower)
path = 'materials/{}'.format(name.lower())
if not os.path.exists('{}.vmt'.format(path)):
LOGGER.warning('material skipped ENOENT: %r %r', name, path)
return
for ext in ['vtf', 'vmt']:
material_ext = '{}.{}'.format(path, ext)
emit_item(material_ext)
def emit_model(path, dedupe):
model_lower = path.lower()
if model_lower in dedupe:
LOGGER.debug('model removd by de-dupe: %r %r', path, model_lower)
return
dedupe.add(model_lower)
LOGGER.debug('model added: %r %r', path, model_lower)
if not os.path.exists(path):
LOGGER.warning('model skipped ENOENT: %r %r', path, model_lower)
return
model_base = os.path.splitext(path)[0]
for ext in ['dx80.vtx', 'dx90.vtx', 'mdl', 'phy', 'sw.vtx', 'vvd']:
model_ext = '{}.{}'.format(model_base, ext)
emit_item(model_ext)
for material in pyvmf.mdl_materials(path):
emit_material(material, dedupe)
def main(argp=None, argv=None):
if argp is None:
argp = ARGP.parse_args()
logging.basicConfig(level=(logging.DEBUG if argp.verbose else logging.INFO))
if not argp.pack_used_local:
LOGGER.info('no operation requested, try --pack-used-local')
return 0
LOGGER.info('loading vmf %r ...', argp.vmf.name)
vmf = pyvmf.Vmf.load(argp.vmf)
LOGGER.info('loading vmf %r ... done', argp.vmf.name)
dedupe = set()
for prop in vmf.iter_props():
model = prop.attributes['model']
emit_model(model, dedupe)
for leaf, material in vmf.iter_materials():
emit_material(material, dedupe)
return 0
argp = ARGP.parse_args()
if not argp.pack_used_local:
exit()
vmf = pyvmf.Vmf.load(argp.vmf)
dedupe = set()
for prop in vmf.iter_props():
model = prop.attributes['model']
model_lower = model.lower()
if model_lower in dedupe:
continue
dedupe.add(model_lower)
if not os.path.exists(model):
continue
model_base = os.path.splitext(model)[0]
for ext in ['dx80.vtx', 'dx90.vtx', 'mdl', 'phy', 'sw.vtx', 'vvd']:
model_ext = '{}.{}'.format(model_base, ext)
print(model_ext)
print(model_ext)
for leaf, material in vmf.iter_materials():
material_lower = 'materials/{}'.format(material.lower())
if material_lower in dedupe:
continue
dedupe.add(material_lower)
if not os.path.exists('{}.vmt'.format(material_lower)):
continue
for ext in ['vtf', 'vmt']:
material_ext = '{}.{}'.format(material_lower, ext)
print(material_ext)
print(material_ext)
if __name__ == "__main__":
exit(main())
......@@ -3,3 +3,4 @@
from pyvmf.vmf import Vmf
from pyvmf.vmt import Vmt
from pyvmf.exceptions import *
from pyvmf.mdl import mdl_materials
import string
def mdl_materials(path):
strings = []
with open(path, 'rb') as fh:
dat = fh.read()
dats = [i for i in dat.split(b'\0') if i]
del dat
after_name = False
for i in dats:
sdat = None
try:
sdat = i.decode()
except UnicodeDecodeError as err:
continue
s2dat = ''.join(i for i in sdat if i in string.printable)
if not s2dat or s2dat != sdat:
continue
if sdat.endswith('.mdl'):
after_name = True
if not after_name:
continue
strings.append(sdat)
# strings = ['ttt_terrorcon\\airplane_2\\aft-gear-port-door.mdl',
# 'default',
# 'static_prop',
# '@idle',
# 'idle',
# 'mybody',
# 'ttt_terrorcon/props/airplane_2/body',
# 'models\\ttt_terrorcon\\plane\\']
model_name = strings[0]
model_default = strings[1]
model_static_prod = strings[2]
model_at = strings[3]
model_idle = strings[4]
model_mybody = strings[5]
remainder = strings[6:]
for item in remainder:
yield item
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment