class MOWDEF_NODE_EXTENSION(MOWDEF_NODE): def __init__(self, parent): self.mdl = None super(MOWDEF_NODE_EXTENSION, self).__init__(parent) def blender_get_root_object(self): if self.mdl: return self.mdl.blender_get_root_object() return None def load_data(self): super(MOWDEF_NODE_EXTENSION, self).load_data() from mowdef_node_root import MOWDEF_NODE_ROOT filename = None # Get the name of the MDL file filename = self.data.split()[1][1:-1] # Build a complete filepath to the .MDL file filename = self.path + filename print(type(self).__name__ + " Loading file " + filename) try: # Create an MDL object and load the MDL file self.mdl = MDL(filename) except: print(sys.exc_info()[0]) def build_blender_scene(self, blender_context, use_animations): if self.mdl: self.mdl.build_blender_scene(blender_context, use_animations)
def load(operator, context, **keywords): time_main = time.time() filepath = keywords['filepath'] # Get rid of all existing objects in the scene for obj in bpy.context.scene.objects: obj.select = obj.type == 'MESH' or obj.type == 'EMPTY' bpy.ops.object.delete() # Process MDL file if filepath != None and os.path.splitext(filepath)[1][1:].strip() == "mdl": mdl = MDL(filepath) mdl.build_blender_scene(context, keywords['use_animations']) mdl.print_type() # Process DEF file elif filepath != None and os.path.splitext(filepath)[1][1:].strip() == "def": mowdef = MOWDEF(filepath) mowdef.build_blender_scene(context, keywords['use_animations']) mowdef.print_type() else: print("No .DEF file found") time_new = time.time() print("finished importing: %r in %.4f sec." % (filepath, (time_new - time_main))) return {'FINISHED'}
def fix_skins(courier_model, flying_courier_model): skins = [ courier_model, flying_courier_model, "models/heroes/bounty_hunter/bounty_hunter.mdl", "models/heroes/lina/lina.mdl", "models/heroes/legion_commander/legion_commander.mdl", "models/heroes/tiny_01/tiny_01.mdl", "models/heroes/tiny_02/tiny_02.mdl", "models/heroes/tiny_03/tiny_03.mdl", "models/heroes/tiny_04/tiny_04.mdl", ] for model in skins: m = MDL() with open(dota_file(model), "rb") as s: m.unpack(s) assert m["numskinfamilies"] != 1, (model, m["numskinfamilies"]) for i in range(1, m["numskinfamilies"].data): m["skin"].field[i].data = m["skin"].field[0].data copy(model, model) if nohats_dir is None: continue with open(nohats_file(model), "r+b") as s: s.seek(m["skinindex"].data) m["skin"].field.pack(s)
def fix_animations(d, visuals, npc_heroes): ignored = ["ACT_DOTA_STATUE_SEQUENCE", "ACT_DOTA_STAUTE_SEQUENCE"] item_activity_modifiers = set() activity_visuals, visuals = filtersplit(visuals, isvisualtype("activity")) for id, key, visual in activity_visuals: asset, modifier = assetmodifier1(visual) item_activity_modifiers.add(modifier) for k, v in npc_heroes["DOTAHeroes"]: if k == "Version": continue model = v["Model"] if not exists(source_file(model)): continue model_parsed = MDL() with open(source_file(model), "rb") as s: model_parsed.unpack(s) sequence_dict = OrderedDict() for sequence in model_parsed["localsequence"]: assert sequence["unused"].data == (0, 0, 0, 0, 0), sequence["unused"].data activity_name = sequence["activitynameindex"].data[1] activity_modifiers = frozenset(am["szindex"].data[1] for am in sequence["activitymodifier"]) sequence_dict.setdefault((activity_name, activity_modifiers), sequence) copied = False for (activity_name, activity_modifiers), sequence in sequence_dict.items(): if activity_name not in ignored and activity_modifiers & item_activity_modifiers: if not copied: copy_model_always(model, model) copied = True orig_activity_modifiers = activity_modifiers - item_activity_modifiers orig_seq = sequence_dict.get((activity_name, orig_activity_modifiers)) if orig_seq is None: orig_seq = sequence_dict.get((activity_name, frozenset())) idle_acts = ["ACT_DOTA_IDLE_RARE", "ACT_DOTA_VICTORY", "ACT_DOTA_TELEPORT", "ACT_DOTA_TELEPORT_END", "ACT_DOTA_SPAWN", "ACT_DOTA_KILLTAUNT", "ACT_DOTA_TAUNT", "ACT_DOTA_LOADOUT"] if orig_seq is None and activity_name in idle_acts: orig_seq = sequence_dict.get(("ACT_DOTA_IDLE", orig_activity_modifiers)) if orig_seq is None and activity_name in ["ACT_DOTA_MOMENT_OF_COURAGE"]: orig_seq = sequence_dict.get(("ACT_DOTA_CAST_ABILITY_3", orig_activity_modifiers)) if orig_seq is None and activity_name in ["ACT_DOTA_ATTACK_PARTICLE", "ACT_DOTA_ATTACK_EVENT_BASH"]: orig_seq = sequence_dict.get(("ACT_DOTA_ATTACK", orig_activity_modifiers)) assert orig_seq is not None, (activity_name, orig_activity_modifiers) print("Replace sequence {} with {}".format(sequence["labelindex"].data[1], orig_seq and orig_seq["labelindex"].data[1])) if nohats_dir is None: continue with open(nohats_file(model), "r+b") as s: new_seq = LocalSequence() new_seq.data = orig_seq.data new_seq["labelindex"].data = sequence["labelindex"].data new_seq["activitynameindex"].data = sequence["activitynameindex"].data new_seq["numactivitymodifier"].data = sequence["numactivitymodifier"].data new_seq["activitymodifierindex"].data = sequence["activitymodifierindex"].data s.seek(sequence["base"].data) new_seq.pack(s) return visuals
def main(): ( _, filename, ) = argv m = MDL() with open(filename, "rb") as s: m.unpack(s) print(m["keyvalue"].data)
def fix_item_model(item, default_item): if default_item is not None: copy_model(default_item["model_player"], item["model_player"]) if has_alternate_skins(item): m = MDL() with open(dota_file(default_item["model_player"]), "rb") as s: m.unpack(s) if m["numskinfamilies"].data != 1: print("Warning: model '{}' has '{}' skin families, need to fix '{}'".format(default_item["model_player"], m["numskinfamilies"].data, item["model_player"]), file=stderr) else: copy_model("models/development/invisiblebox.mdl", item["model_player"])
def fix_animations(d, visuals, npc_heroes): ignored = ["ACT_DOTA_TAUNT", "ACT_DOTA_LOADOUT"] item_activities = set() activity_visuals, visuals = filtersplit(visuals, isvisualtype("activity")) for id, key, visual in activity_visuals: asset, modifier = assetmodifier1(visual) item_activities.add(modifier) for id, gem in d["items_game"]["anim_modifiers"]: modifier = gem["name"] item_activities.add(modifier) for k, v in npc_heroes["DOTAHeroes"]: if k == "Version": continue model = v["Model"] if not exists(dota_file(model)): continue mung_offsets = set() mung_sequence_names = set() model_parsed = MDL() with open(dota_file(model), "rb") as s: model_parsed.unpack(s) for sequence in model_parsed.data["localsequence"]: if sequence["activitynameindex"][1] in ignored: continue for activitymodifier in sequence["activitymodifier"]: if activitymodifier["szindex"][1] in item_activities: mung_offsets.add(activitymodifier["szindex"][0]) mung_sequence_names.add(sequence["labelindex"][1]) if not mung_offsets: continue copy(model, model) for mung_sequence_name in sorted(list(mung_sequence_names)): print("Munging sequence '{}'".format(mung_sequence_name)) if nohats_dir is None: continue with open(nohats_file(model), "r+b") as s: for offset in mung_offsets: s.seek(offset) assert s.read(1) not in [b"X", b""] s.seek(offset) s.write(b"X") return visuals
def model_set_kv(s, kv): m = MDL() m.unpack(s) s.seek(0, SEEK_END) b = kv.encode("ascii") + b"\0" print(kv) print(s.tell()) print(len(b)) m["keyvalueindex"].data = s.tell() m["keyvaluesize"].data = len(b) s.write(b) s.seek(0) m.pack(s)
def load_data(self): super(MOWDEF_NODE_EXTENSION, self).load_data() from mowdef_node_root import MOWDEF_NODE_ROOT filename = None # Get the name of the MDL file filename = self.data.split()[1][1:-1] # Build a complete filepath to the .MDL file filename = self.path + filename print(type(self).__name__ + " Loading file " + filename) try: # Create an MDL object and load the MDL file self.mdl = MDL(filename) except: print(sys.exc_info()[0])
def load(operator, context, **keywords): time_main = time.time() filepath = keywords['filepath'] # Get rid of all existing objects in the scene for obj in bpy.context.scene.objects: obj.select = obj.type == 'MESH' or obj.type == 'EMPTY' bpy.ops.object.delete() # Process MDL file if filepath != None and os.path.splitext(filepath)[1][1:].strip() == "mdl": mdl = MDL(filepath) mdl.build_blender_scene(context, keywords['use_animations']) mdl.print_type() # Process DEF file elif filepath != None and os.path.splitext( filepath)[1][1:].strip() == "def": mowdef = MOWDEF(filepath) mowdef.build_blender_scene(context, keywords['use_animations']) mowdef.print_type() else: print("No .DEF file found") time_new = time.time() print("finished importing: %r in %.4f sec." % (filepath, (time_new - time_main))) return {'FINISHED'}
def fix_base_models(visuals, heroes): # fix hero base model overrides (TB arcana) entity_model_visuals, visuals = filtersplit(visuals, isvisualtype("base_model")) for asset, modifier in assetmodifier(entity_model_visuals): asset_model = heroes["DOTAHeroes"][asset]["Model"] copy_model(asset_model, modifier) # special case to fix mismatched activities if modifier == "models/heroes/crystal_maiden/crystal_maiden_arcana.mdl": print("Applying activity fix to crystal_maiden_arcana.mdl") f = nohats_file(modifier) m = MDL() with open(f, "rb") as s: m.unpack(s) for seq in m["localsequence"]: if seq["labelindex"].data[1] == "cm_attack2" and seq["activitynameindex"].data[1] == "ACT_DOTA_ATTACK" and len(seq["activitymodifier"]) == 0: sequence = seq break else: assert False, "Can't find sequence to edit" with open(f, "r+b") as s: s.seek(0, SEEK_END) o = s.tell() s.write(b"ACT_DOTA_ATTACK2\0") while s.tell() % 4 != 0: s.write(b"\0") total_size = s.tell() sequence["activitynameindex"].data = [o, "ACT_DOTA_ATTACK2"] s.seek(sequence["base"].data) sequence.pack(s) m["datalength"].data = total_size s.seek(0) m.pack(s) return visuals
def main(): (_, filename,) = argv m = MDL() with open(filename, "rb") as s: m.unpack(s) print(m["keyvalue"].data)
# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software Foundation, # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # # ##### END GPL LICENSE BLOCK ##### # Men of War MDL importer for Blender # Script Copyright (C) by Björn Martins Paz import argparse import os import struct from mdl import MDL from mowdef import MOWDEF parser = argparse.ArgumentParser() parser.add_argument('infile', nargs='?', help='Input file') args = parser.parse_args() infile = args.infile # Process MDL file if infile != None and os.path.splitext(infile)[1][1:].strip() == "mdl": mdl = MDL(infile) # Process DEF file elif infile != None and os.path.splitext(infile)[1][1:].strip() == "def": mowdef = MOWDEF(infile) else: print("No .MDL or .DEF file found") parser.print_help()