Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import sys
- from xml.etree.ElementTree import Element
- from utils import walk_dir_xml
- from element_data import ElementData, ElementProperty, StringProperty, FloatProperty, IntProperty, Vector3Property, Vector4Property
- from dataclasses import dataclass
- RESULTS_FILE = "results_unkushort1.txt"
- RESULTS_FILE_VERBOSE = "results_unkushort1_verbose.txt"
- XML_DIR = "./yft"
- # Determine if an UnkUshort1 value exists in the file that either
- # 1. Is an invalid shader index
- # 2. Is a valid shader index but not a "vehicle_vehglass" shader
- def has_invalid_unkushort1(element: Element):
- shaders = element.findall(".//Shaders/*")
- unkushort1s = element.iterfind(".//UnkUshort1")
- for unkushort1 in unkushort1s:
- index = int(unkushort1.attrib["value"]) - 1
- if index >= len(shaders):
- return True
- shader = shaders[index]
- if not "vehicle_vehglass" in shader.find("Name").text:
- return True
- return False
- def has_windows(element: Element):
- return element.find(".//VehicleGlassWindows/*")
- def percent(value: float) -> str:
- return f"{round(value, 3) * 100}%"
- def print_status(i, n):
- j = (i + 1) / n
- sys.stdout.write('\r')
- # the exact output you're looking for:
- sys.stdout.write("[%-20s] %d%%" % ('='*int(20*j), 100*j))
- sys.stdout.flush()
- with open(RESULTS_FILE, "w") as f, open(RESULTS_FILE_VERBOSE, "w") as f2:
- num_files = len(os.listdir(XML_DIR))
- num_invalid_unkushort1s = 0
- current_file = 1
- files_with_windows = []
- for filename, doc in walk_dir_xml(XML_DIR):
- if not has_windows(doc):
- continue
- files_with_windows.append((filename, doc))
- num_yfts_with_windows = len(files_with_windows)
- for filename, doc in files_with_windows:
- # Messages for verbose file
- verbose_messages = []
- # Progress bar
- print_status(current_file, num_yfts_with_windows)
- if has_invalid_unkushort1(doc):
- num_invalid_unkushort1s += 1
- verbose_messages.append(
- "Has an UnkUshort1 that does not lead to a vehicle_vehglass shader!\n")
- current_file += 1
- if verbose_messages:
- f2.write(f"======{filename}=======\n")
- for msg in verbose_messages:
- f2.write(msg)
- percent_invalid_unkushort1s = percent(
- num_invalid_unkushort1s/num_yfts_with_windows)
- f.write(f"In {percent_invalid_unkushort1s} yft(s) with windows, there were UnkUshort1 values that did not lead to a vehicle_vehglass shader.\n")
- f.write(f"Tested {num_yfts_with_windows} yft(s) with windows.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement