bot_editor.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # Script to manipulate zoffline bot files
  2. #
  3. # Route ID can be found in http://cdn.zwift.com/gameassets/GameDictionary.xml (signature)
  4. #
  5. # Type .position in chat to find start road and roadTime, the values will be printed in console
  6. # Choose a position where the bot passes both times at the same speed to have a smooth loop
  7. import os
  8. import sys
  9. import csv
  10. sys.path.insert(0, '../protobuf')
  11. import profile_pb2
  12. import udp_node_msgs_pb2
  13. try:
  14. input = raw_input
  15. except NameError:
  16. pass
  17. def road_id(state):
  18. return (state.aux3 & 0xff00) >> 8
  19. def is_forward(state):
  20. return (state.f19 & 4) != 0
  21. def get_course(state):
  22. return (state.f19 & 0xff0000) >> 16
  23. def delete(s, i):
  24. print('course %s road %s isForward %s roadTime %s' % (get_course(s[i]), road_id(s[i]), is_forward(s[i]), s[i].roadTime))
  25. del s[i]
  26. def file_exists(file):
  27. if not os.path.isfile(file):
  28. print('%s not found\n' % file)
  29. return False
  30. return True
  31. PROFILE_FILE = 'profile.bin'
  32. if file_exists(PROFILE_FILE):
  33. p = profile_pb2.PlayerProfile()
  34. with open(PROFILE_FILE, 'rb') as f:
  35. p.ParseFromString(f.read())
  36. p.id = int(input("Player ID: "))
  37. p.first_name = input("First name: ")
  38. p.last_name = input("Last name: ")
  39. for a in p.public_attributes:
  40. #0x69520F20=1766985504 - crc32 of "PACE PARTNER - ROUTE"
  41. if a.id == 1766985504:
  42. a.number_value = int(input("Route ID: "))
  43. with open(PROFILE_FILE, 'wb') as f:
  44. f.write(p.SerializeToString())
  45. ROUTE_FILE = 'route.bin'
  46. if file_exists(ROUTE_FILE):
  47. g = udp_node_msgs_pb2.Ghost()
  48. with open(ROUTE_FILE, 'rb') as f:
  49. g.ParseFromString(f.read())
  50. start_road = int(input("Start road: "))
  51. start_rt = int(input("Start roadTime: "))
  52. print('Deleted records:\n')
  53. try:
  54. while road_id(g.states[0]) != start_road:
  55. delete(g.states, 0)
  56. while road_id(g.states[-1]) != start_road:
  57. delete(g.states, -1)
  58. if is_forward(g.states[0]):
  59. while g.states[0].roadTime < start_rt or abs(g.states[0].roadTime - start_rt) > 500000:
  60. delete(g.states, 0)
  61. while g.states[-1].roadTime > start_rt or abs(g.states[-1].roadTime - start_rt) > 500000:
  62. delete(g.states, -1)
  63. else:
  64. while g.states[0].roadTime > start_rt or abs(g.states[0].roadTime - start_rt) > 500000:
  65. delete(g.states, 0)
  66. while g.states[-1].roadTime < start_rt or abs(g.states[-1].roadTime - start_rt) > 500000:
  67. delete(g.states, -1)
  68. except IndexError:
  69. pass
  70. with open(ROUTE_FILE, 'wb') as f:
  71. f.write(g.SerializeToString())
  72. print('\nDone')