dir = "BattalionWars/BW1/Data/CompoundFiles" files = os.listdir(dir) out = "test.res" sub_sections = [b"RXET", b"PRCS"] for filename in files: if not filename.endswith(".res"): continue path = os.path.join(dir, filename) with open(path, "rb") as f: arc = BWArchive(f) with open(out, "wb") as f: arc.write(f) with open(path, "rb") as f: test1 = f.read() with open(out, "rb") as f: test2 = f.read() print(path, out) print(test1 == test2) print(len(test1), len(test2)) #assert test1 == test2
out_res_modded = out_res_filename+"" out_xml_modded = out_xml_filename+"" # Read the xml files for the two levels with open(os.path.join(in_dir, in_xml_filename), "r") as f: in_xml = BattWarsLevel(f) with open(os.path.join(in_dir, out_xml_filename), "r") as f: out_xml = BattWarsLevel(f) # Read the res files for the two levels with open(os.path.join(in_dir, in_res_filename), "rb") as f: in_res = BWArchive(f) with open(os.path.join(in_dir, out_res_filename), "rb") as f: out_res = BWArchive(f) graph = calc_dependency_graph(in_xml) #battlestation = "2138048269" unit_base_id = "2138048269" #WF Battlestation #unit_base_id = "2138051207" #SolarEmpire Heavy Tank bsta_dependencies = get_dependencies(graph, unit_base_id) model, tex, additional = get_model_data(in_xml, in_res, b"VWFBSTAH") #additional = ["2138046784", "2138046782", "2138046783", "250000932"] Textures for Battlestation #additional = ["1850000107"] # Textures for SE Heavy Tank #bsta_dependencies.append("2138046784") assert all(x not in bsta_dependencies for x in additional) bsta_dependencies.extend(additional) needed_dependencies = [dep for dep in filter(lambda x: x not in out_xml.obj_map, bsta_dependencies)]
import os from bw_archive.bw_archive import BWArchive from bw_read_xml import BattWarsLevel in_dir = os.path.join("BattalionWars", "BW1", "Data", "CompoundFiles") res_files = filter(lambda x: x.endswith(".res"), os.listdir(in_dir)) types = {} for filename in res_files: path = os.path.join(in_dir, filename) xmlpath = path[:-4]+".xml" print("---", filename, "---") with open(path, "rb") as f: bw_arc = BWArchive(f) with open(xmlpath, "r") as f: bw_xml = BattWarsLevel(f) #print("--------------------------\n") #print(filename) #print([ (entry.name, bytes(entry.res_name)) for entry in filter(lambda x:x.name == b"PRCS", bw_arc.entries)]) for obj_id, obj in bw_xml.obj_map.items(): for attr in obj.attributes: if obj.has_attr("mName"): assert obj.get_attr_type("mName") == "cFxString8" if obj.type == "cTroop" and obj.get_attr_value("mName") is not None: print(obj.get_attr_value("mName")) types[obj.type] = True