get_start_lines.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import os
  2. import xml.etree.ElementTree as ET
  3. import re
  4. import json
  5. import subprocess
  6. worlds = 'C:\\Program Files (x86)\\Zwift\\assets\\Worlds'
  7. world_names = {
  8. '1': 'Watopia',
  9. '2': 'Richmond',
  10. '3': 'London',
  11. '4': 'New York',
  12. '5': 'Innsbruck',
  13. '6': 'Bologna',
  14. '7': 'Yorkshire',
  15. '8': 'Crit City',
  16. '9': 'Makuri Islands',
  17. '10': 'France',
  18. '11': 'Paris',
  19. '12': 'Gravel Mountain',
  20. '13': 'Scotland'
  21. }
  22. data = {}
  23. for directory in os.listdir(worlds):
  24. world = directory[5:]
  25. if os.path.isdir(os.path.join(worlds, directory)) and world in world_names:
  26. subprocess.run(['wad_unpack.exe', os.path.join(worlds, directory, 'data_1.wad')])
  27. routes = os.path.join('Worlds', directory, 'routes')
  28. for file in os.listdir(routes):
  29. with open(os.path.join(routes, file)) as f:
  30. xml = f.read()
  31. tree = ET.fromstring(re.sub(r"(<\?xml[^>]+\?>)", r"\1<root>", xml) + "</root>")
  32. route = tree.find('route')
  33. nameHash = int.from_bytes(int(route.get('nameHash')).to_bytes(4, 'little'), 'little', signed=True)
  34. checkpoints = list(tree.find('highrescheckpoint').iter('entry'))
  35. data[nameHash] = {
  36. 'name': '%s - %s' % (world_names[world], route.get('name').strip()),
  37. 'road': int(checkpoints[0].get('road')),
  38. 'time': int(float(checkpoints[0].get('time')) * 1000000 + 5000)
  39. }
  40. with open('../data/start_lines.txt', 'w') as f:
  41. json.dump({k: v for k, v in sorted(data.items(), key=lambda d: d[1]['name'])}, f, indent=2)