Julien-Bernard

Desync investigation script

Jun 16th, 2021
950
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import slippi
  2. import json
  3.  
  4. gTheirs = slippi.Game("C:/Users/julbe/Documents/Slippi/desync/replays/replays/Game_20210508T160828.slp")
  5. gMine = slippi.Game("C:/Users/julbe/Documents/Slippi/desync/replaysMySide/Game_20210508T230826.slp")
  6.  
  7. # m = min(len(gTheirs.frames),len(gMine.frames))
  8. #
  9. # positionsTheirs = [gTheirs.frames[i].ports[1].leader.pre.position for i in range(m)]
  10. # positionsMine = [gMine.frames[i].ports[1].leader.pre.position for i in range(m)]
  11. #
  12. # stickTheirs = [gTheirs.frames[i].ports[1].leader.pre.joystick for i in range(m)]
  13. # stickMine = [gMine.frames[i].ports[1].leader.pre.joystick for i in range(m)]
  14. #
  15. # desyncedPos = [i for i in range(len(positionsTheirs)) if positionsMine[i] != positionsTheirs[i]]
  16. # desyncedStick = [i for i in range(m) if stickMine[i] != stickTheirs[i]]
  17.  
  18.  
  19. from slippi.parse import parse
  20. from slippi.parse import ParseEvent
  21.  
  22. framesTheirs=[]
  23. handlers = {ParseEvent.FRAME: framesTheirs.append}
  24. parse('C:/Users/julbe/Documents/Slippi/desync/replays/replays/Game_20210508T160828.slp', handlers)
  25.  
  26. framesMine=[]
  27. handlers = {ParseEvent.FRAME: framesMine.append}
  28. parse("C:/Users/julbe/Documents/Slippi/desync/replaysMySide/Game_20210508T230826.slp", handlers)
  29.  
  30. maxIndexTheirs = 0
  31. definitiveFramesTheirs={}
  32. for frame in framesTheirs:
  33.     if frame.index > maxIndexTheirs:
  34.         maxIndexTheirs = frame.index+124
  35.     definitiveFramesTheirs[frame.index+124] = frame
  36.  
  37. maxIndexMine = 0
  38. definitiveFramesMine={}
  39. for frame in framesMine:
  40.     if frame.index > maxIndexMine:
  41.         maxIndexMine = frame.index+124
  42.     definitiveFramesMine[frame.index+124] = frame
  43.  
  44. framesListMine={}
  45. for frame in framesMine:
  46.     if frame.index+124 not in framesListMine:
  47.         framesListMine[frame.index+124]=[]
  48.     framesListMine[frame.index+124].append(frame)
  49.  
  50. frameIndexesMine = [frame.index+124 for frame in framesMine]
  51.  
  52. m = min(maxIndexMine,maxIndexTheirs)-1
  53.  
  54. f_positionsTheirs = [definitiveFramesTheirs[i].ports[1].leader.pre.position for i in range(1,maxIndexTheirs)]
  55. f_positionsMine = [definitiveFramesMine[i].ports[1].leader.pre.position for i in range(1,maxIndexMine)]
  56.  
  57. f_stickTheirs = [definitiveFramesTheirs[i].ports[1].leader.pre.joystick for i in range(1,maxIndexTheirs)]
  58. f_stickMine = [definitiveFramesMine[i].ports[1].leader.pre.joystick for i in range(1,maxIndexMine)]
  59.  
  60. f_cstickTheirs = [definitiveFramesTheirs[i].ports[1].leader.pre.cstick for i in range(1, maxIndexTheirs)]
  61. f_cstickMine = [definitiveFramesMine[i].ports[1].leader.pre.cstick for i in range(1, maxIndexMine)]
  62.  
  63. f_preTheirs = [definitiveFramesTheirs[i].ports[1].leader.pre for i in range(1, maxIndexTheirs)]
  64. f_preMine = [definitiveFramesMine[i].ports[1].leader.pre for i in range(1, maxIndexMine)]
  65.  
  66. f_desyncedPos = [i+1 for i in range(m) if f_positionsMine[i] != f_positionsTheirs[i]]
  67. f_desyncedStick = [i+1 for i in range(m) if f_stickMine[i] != f_stickTheirs[i]]
  68. f_desyncedCStick = [i+1 for i in range(m) if f_cstickMine[i] != f_cstickTheirs[i]]
  69. f_desyncedPre = [i+1 for i in range(m) if f_preMine[i] != f_preTheirs[i]]
  70.  
  71.  
  72. m_stickTheirs = [definitiveFramesTheirs[i].ports[0].leader.pre.joystick for i in range(1, maxIndexTheirs)]
  73. m_stickMine = [definitiveFramesMine[i].ports[0].leader.pre.joystick for i in range(1, maxIndexMine)]
  74.  
  75. m_cstickTheirs = [definitiveFramesTheirs[i].ports[0].leader.pre.cstick for i in range(1, maxIndexTheirs)]
  76. m_cstickMine = [definitiveFramesMine[i].ports[0].leader.pre.cstick for i in range(1, maxIndexMine)]
  77.  
  78. m_desyncedStick = [i+1 for i in range(m) if m_stickMine[i] != m_stickTheirs[i]]
  79. m_desyncedCStick = [i+1 for i in range(m) if m_cstickMine[i] != m_cstickMine[i]]
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87. #########################################
  88.  
  89. # Split logs into games
  90.  
  91. def parseLogs(logsLines):
  92.     """08:44:787 Core\HW\EXI_DeviceSlippi.cpp:2662 W[SLIPPI]: Frame 4193 player 0 X 0 21712 256 2"""
  93.     """10:24:906 Core\Slippi\SlippiNetplay.cpp:444 I[SLIPPI_ONLINE]: [Netplay] Received selections from opponent with player idx 1"""
  94.     # Split into games
  95.     games = [[]]
  96.     for line in logsLines:
  97.         if u"Core\HW\EXI_DeviceSlippi.cpp:2662 W[SLIPPI]: Frame 1 " in line:
  98.             games.append([])
  99.         else:
  100.             games[-1].append(line)
  101.     return games
  102.  
  103.  
  104. logsMine = open("C:/Users/julbe/OneDrive/TAAQ-Desktop/PyCharmProjects/logsComp/mine.log", 'r')
  105. logsMineLines = logsMine.readlines()
  106. gamesMine = parseLogs(logsMineLines)
  107.  
  108. logsTheirs = open("C:/Users/julbe/OneDrive/TAAQ-Desktop/PyCharmProjects/logsComp/theirs.log", 'r')
  109. logsTheirsLines = logsTheirs.readlines()
  110. gamesTheirs = parseLogs(logsTheirsLines)
  111.  
  112. # for i in range(27):
  113. #     with open("C:/Users/julbe/OneDrive/TAAQ-Desktop/PyCharmProjects/logsComp/games/mineGame"+str(i)+".log",'w+') as fileMine:
  114. #         for line in gamesMine[i]:
  115. #             fileMine.write(line)
  116. # for i in range(27):
  117. #     with open("C:/Users/julbe/OneDrive/TAAQ-Desktop/PyCharmProjects/logsComp/games/theirsGame"+str(i)+".log",'w+') as fileTheirs:
  118. #         for line in gamesTheirs[i]:
  119. #             fileTheirs.write(line)
  120.  
  121. # Seek differences in inputs
  122.  
  123. import os
  124.  
  125. def investigate(folderStr):
  126.     # Obtain both frame lists
  127.  
  128.     directory = os.fsencode(folderStr)
  129.  
  130.     framesPacks = []
  131.  
  132.     for file in os.listdir(directory):
  133.         filename = os.fsdecode(file)
  134.         if filename.endswith(".slp"):
  135.             print(filename)
  136.             frames = []
  137.             handlers = {ParseEvent.FRAME: frames.append}
  138.             try:
  139.                 parse(folderStr+"/"+filename, handlers)
  140.             except:
  141.                 print("error")
  142.             framesPacks.append(frames)
  143.  
  144.     return framesPacks
  145.  
  146. replayFolder = "replayComp2"
  147. framesPacksMine = investigate("C:/Users/julbe/OneDrive/TAAQ-Desktop/PyCharmProjects/"+replayFolder+"/mine")
  148. framesPacksTheirs = investigate("C:/Users/julbe/OneDrive/TAAQ-Desktop/PyCharmProjects/"+replayFolder+"/theirs")
  149.  
  150. definitiveFramesMine = []
  151. definitiveFramesTheirs = []
  152.  
  153. stickTheirs0 = []
  154. stickMine0 = []
  155. stickTheirs1 = []
  156. stickMine1 = []
  157.  
  158. desyncedStick0 = []
  159. desyncedStick1 = []
  160.  
  161. # 26
  162. for i in range(16):
  163.  
  164.     maxIndexMine = 0
  165.     definitiveFramesMine.append({})
  166.     definitiveFramesTheirs.append({})
  167.  
  168.     for frame in framesPacksMine[i]:
  169.         if frame.index > maxIndexMine:
  170.             maxIndexMine = frame.index+123
  171.         definitiveFramesMine[i][frame.index+123] = frame
  172.  
  173.     maxIndexTheirs = 0
  174.  
  175.     for frame in framesPacksTheirs[i]:
  176.         if frame.index > maxIndexTheirs:
  177.             maxIndexTheirs = frame.index + 123
  178.         definitiveFramesTheirs[i][frame.index + 123] = frame
  179.  
  180.     stickTheirs0.append([definitiveFramesTheirs[i][j].ports[0].leader.pre.joystick for j in range(maxIndexTheirs)])
  181.     stickMine0.append([definitiveFramesMine[i][j].ports[0].leader.pre.joystick for j in range(maxIndexMine)])
  182.     stickTheirs1.append([definitiveFramesTheirs[i][j].ports[1].leader.pre.joystick for j in range(maxIndexTheirs)])
  183.     stickMine1.append([definitiveFramesMine[i][j].ports[1].leader.pre.joystick for j in range(maxIndexMine)])
  184.  
  185.     m = min(maxIndexMine, maxIndexTheirs)
  186.  
  187.     desyncedStick0.append([j for j in range(m) if stickMine0[i][j] != stickTheirs0[i][j]])
  188.     desyncedStick1.append([j for j in range(m) if stickMine1[i][j] != stickTheirs1[i][j]])
  189.  
  190. # desyncedStick0
  191. # [[], [76, 77], [], [], [], [], [], [], [], [45, 46, 47, 55, 57, 58, 59], [], [], [], [54, 55, 56, 57, 60, 61, 62], [57, 58, 59, 72, 73, 74], [], [12074], [], [], [], [], [], [], [], [], []]
  192. # desyncedStick1
  193. # [[], [], [], [], [], [], [], [], [], [], [], [], [], [], [77], [], [], [], [42, 43, 45, 49, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73], [4848], [], [], [], [], [], []]
  194. # desyncedStick1[20]
  195. # []
  196. # desyncedStick1[21]
  197. # []
  198. # desyncedStick1[19]
  199. # [4848]
  200. # stickTheirs1[19][4848-1:4848+2]
  201. # [(-0.99, 0.00), (-0.99, 0.00), (-0.99, 0.00)]
  202. # stickMine1[19][4848-1:4848+2]
  203. # [(-0.99, 0.00), (0.00, 0.00), (-0.99, 0.00)]
  204.  
  205. #index 19 -> game "20"
RAW Paste Data