Advertisement
Guest User

Untitled

a guest
Apr 30th, 2014
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 24.12 KB | None | 0 0
  1. '''
  2. Format of command stream:
  3. //
  4. // repeat {
  5. //   uint8 - message typecode (ECmdStreamOp)
  6. //   uint16 - length of message (including header)
  7. //   ... - op specific data
  8. // }
  9. //
  10. enum ECmdStreamOp
  11. {
  12.  
  13. 0    CMDST_Advance,
  14.    // uint32 - number of beats to advance.
  15.  
  16. 1    CMDST_SetCommandSource,
  17.    // uint8 - command source
  18.  
  19. 2    CMDST_CommandSourceTerminated,
  20.    // no args.
  21.  
  22. 3    CMDST_VerifyChecksum,
  23.    // MD5Digest - checksum
  24.    // uint32 - beat number
  25.  
  26. 4    CMDST_RequestPause,
  27. 5    CMDST_Resume,
  28. 6    CMDST_SingleStep,
  29.    // All with no additional data.
  30.  
  31. 7    CMDST_CreateUnit,
  32.    // uint8 - army index
  33.    // string - blueprint ID
  34.    // float - x
  35.    // float - z
  36.    // float - heading
  37.  
  38. 8    CMDST_CreateProp,
  39.    // string - blueprint ID
  40.    // Vector3f - location
  41.  
  42. 9   CMDST_DestroyEntity,
  43.    // EntId - entity
  44.  
  45. 10    CMDST_WarpEntity,
  46.    // EntId - entity
  47.    // VTransform - new transform
  48.    
  49. 11    CMDST_ProcessInfoPair,
  50.    // EntId - entity
  51.    // string - arg1
  52.    // string - arg2
  53.  
  54. 12    CMDST_IssueCommand,
  55.    // uint32 - num units
  56.    // EntIdSet - units
  57.    // CmdData - command data
  58.    // uint8 - clear queue flag
  59.  
  60. 13    CMDST_IssueFactoryCommand,
  61.    // uint32 - num factories
  62.    // EntIdSet - factories
  63.    // CmdData - command data
  64.    // uint8 - clear queue flag
  65.  
  66. 14    CMDST_IncreaseCommandCount,
  67.    // CmdId - command id
  68.    // int32 - count delta
  69.  
  70. 15    CMDST_DecreaseCommandCount,
  71.    // CmdId - command id
  72.    // int32 - count delta
  73.  
  74. 16    CMDST_SetCommandTarget,
  75.    // CmdId - command id
  76.    // STITarget - target
  77.  
  78. 17    CMDST_SetCommandType,
  79.    // CmdId - command id
  80.    // EUnitCommandType - type
  81.  
  82.  
  83. 18    CMDST_SetCommandCells,
  84.    // CmdId - command id
  85.    // ListOfCells - list of cells
  86.    // Vector3f - pos
  87.  
  88. 19    CMDST_RemoveCommandFromQueue,
  89.    // CmdId - command id
  90.    // EntId - unit
  91.  
  92. 20    CMDST_DebugCommand,
  93.    // string -- the debug command string
  94.    // Vector3f -- mouse pos (in world coords)
  95.    // uint8 -- focus army index
  96.    // EntIdSet -- selection
  97.  
  98. 21    CMDST_ExecuteLuaInSim,
  99.    // string -- the lua string to evaluate in the sim state
  100.  
  101. 22    CMDST_LuaSimCallback,
  102.    // string - callback function name
  103.    // LuaObject - table of function arguments
  104.  
  105. 21    CMDST_EndGame,
  106.    // no args.
  107. };
  108.  
  109.  
  110. // Format of EntIdSet:
  111. //
  112. // uint32 - number of entity ids
  113. // repeat number of entity ids times {
  114. //   EndId - entity id
  115. // }
  116.  
  117.  
  118. // Format of CmdData:
  119. //
  120. // CmdId - id
  121. // uint8 - command type (EUnitCommandType)
  122. // STITarget - target
  123. // int32 - formation index or -1
  124. // if formation index != -1
  125. // {
  126. //   Quaternionf - formation orientation
  127. //   float - formation scale
  128. // }
  129. // string - blueprint ID or the empty string for no blueprint
  130. // ListOfCells - cells
  131. // int32 - count
  132.  
  133.  
  134. // Format of STITarget:
  135. //
  136. // uint8 - target type (ESTITargetType)
  137. // if target type == STITARGET_Entity {
  138. //   EntId - entity id
  139. // }
  140. // if target type == STITARGET_Position {
  141. //   Vector3f - position
  142. // }
  143.  
  144.  
  145. // Format of ListOfCells:
  146. //
  147. // uint32 - num cells
  148. // repeat num cells times {
  149. //   int16 - x
  150. //   int16 - z
  151. // }
  152. '''
  153.  
  154. class UNITCOMMAND(object):
  155.     UNITCOMMAND_None = 0
  156.     UNITCOMMAND_Stop = 1
  157.     UNITCOMMAND_Move = 2
  158.     UNITCOMMAND_Dive = 3
  159.     UNITCOMMAND_FormMove = 4
  160.     UNITCOMMAND_BuildSiloTactical =5
  161.     UNITCOMMAND_BuildSiloNuke =6
  162.     UNITCOMMAND_BuildFactory =7
  163.     UNITCOMMAND_BuildMobile =8
  164.     UNITCOMMAND_BuildAssist =9
  165.     UNITCOMMAND_Attack =10
  166.     UNITCOMMAND_FormAttack =11
  167.     UNITCOMMAND_Nuke =12
  168.     UNITCOMMAND_Tactical =13
  169.     UNITCOMMAND_Teleport =14
  170.     UNITCOMMAND_Guard =15
  171.     UNITCOMMAND_Patrol =16
  172.     UNITCOMMAND_Ferry =17
  173.     UNITCOMMAND_FormPatrol =18
  174.     UNITCOMMAND_Reclaim =19
  175.     UNITCOMMAND_Repair =20
  176.     UNITCOMMAND_Capture =21
  177.     UNITCOMMAND_TransportLoadUnits =22
  178.     UNITCOMMAND_TransportReverseLoadUnits =23
  179.     UNITCOMMAND_TransportUnloadUnits =24
  180.     UNITCOMMAND_TransportUnloadSpecificUnits =25
  181.     UNITCOMMAND_DetachFromTransport =26
  182.     UNITCOMMAND_Upgrade =27
  183.     UNITCOMMAND_Script =28
  184.     UNITCOMMAND_AssistCommander =29
  185.     UNITCOMMAND_KillSelf =30
  186.     UNITCOMMAND_DestroySelf =31
  187.     UNITCOMMAND_Sacrifice =32
  188.     UNITCOMMAND_Pause =33
  189.     UNITCOMMAND_OverCharge =34
  190.     UNITCOMMAND_AggressiveMove =35
  191.     UNITCOMMAND_FormAggressiveMove =36
  192.     UNITCOMMAND_AssistMove =37
  193.     UNITCOMMAND_SpecialAction =38
  194.     UNITCOMMAND_Dock =39
  195.  
  196.  
  197. '''
  198. // Format of CmdData:
  199. //
  200. // CmdId - id
  201. // uint8 - command type (EUnitCommandType)
  202. // STITarget - target
  203. // int32 - formation index or -1
  204. // if formation index != -1
  205. // {
  206. //   Quaternionf - formation orientation
  207. //   float - formation scale
  208. // }
  209. // string - blueprint ID or the empty string for no blueprint
  210. // ListOfCells - cells
  211. // int32 - count
  212.  
  213. // Format of STITarget:
  214. //
  215. // uint8 - target type (ESTITargetType)
  216. // if target type == STITARGET_Entity {
  217. //   EntId - entity id
  218. // }
  219. // if target type == STITARGET_Position {
  220. //   Vector3f - position
  221. // }
  222.  
  223.  
  224. // Format of ListOfCells:
  225. //
  226. // uint32 - num cells
  227. // repeat num cells times {
  228. //   int16 - x
  229. //   int16 - z
  230. // }
  231.  
  232. // Format of EntIdSet:
  233. //
  234. // uint32 - number of entity ids this may be gone
  235. // repeat number of entity ids times {
  236. //   EndId - entity id
  237. // }'''
  238.  
  239.  
  240.  
  241.  
  242. import struct
  243. from replayArmy import *
  244. from replayArmyContainer import *
  245. from replayInfos import *
  246. #from replayOptions import *
  247.  
  248. import json
  249. from PyQt4 import  QtCore
  250.  
  251. TYPE_NUMBER = 0
  252. TYPE_STRING = 1
  253. TYPE_NIL = 2
  254. TYPE_BOOLEAN = 3
  255. TABLE_BEGIN = 4
  256. TABLE_END = 5
  257.  
  258.  
  259. class replayParser(object):
  260.     def __init__(self, replayfile):
  261.  
  262.         replay = open(inFile, "rt")
  263.         info = json.loads(replay.readline())
  264.  
  265.         self.bin = QtCore.qUncompress(QtCore.QByteArray.fromBase64(replay.read()))
  266.         replay.close()        
  267.  
  268.         #f = open(inFile, 'rb')
  269.         #self.bin = f.read()
  270.         self.offset= 0
  271.         self.supcomVersion = ""
  272.         self.replayVersion = ""
  273.         self.players = []
  274.  
  275.  
  276.     def readLine(self, offset):
  277.         line = ''
  278.         while True :
  279.            
  280.             char = struct.unpack("s", self.bin[offset:offset+1])
  281.    
  282.             offset = offset + 1
  283.             #print char
  284.             if char[0] == '\r' :
  285.                 #offset = offset + 2
  286.                 break
  287.             elif char[0] == '\x00' :
  288.                 #offset = offset + 3
  289.                 break
  290.             else :
  291.                 line = line + char[0]
  292.         return offset, line
  293.    
  294.     def readInt(self, offset):
  295.         int = struct.unpack("i", self.bin[offset:offset+4])[0]
  296.         return offset+4, int
  297.    
  298.     def readUInt(self, offset):
  299.         int = struct.unpack("I", self.bin[offset:offset+4])[0]
  300.         return offset+4, int
  301.  
  302.    
  303.     def readChar(self, offset):
  304.         char = struct.unpack("B", self.bin[offset:offset+1])[0]
  305.         return offset+1, char
  306.  
  307.    
  308.     def readShort(self, offset):
  309.         int = struct.unpack("H", self.bin[offset:offset+2])[0]
  310.         return offset+2, int
  311.    
  312.     def readFloat(self, offset):
  313.         float = struct.unpack("f", self.bin[offset:offset+4])[0]
  314.         return offset+4, float
  315.    
  316.    
  317.     def readBool(self, offset):
  318.         bool = struct.unpack("?", self.bin[offset:offset+1])[0]
  319.         return offset+1, bool
  320.    
  321.    
  322.     def peekType(self, data):
  323.         result = struct.unpack("b", data[0:1])
  324.         return result[0]
  325.    
  326.     def parseLua(self, offset):
  327.    
  328.         type = struct.unpack("b", self.bin[offset:offset+1])[0]
  329.         offset = offset + 1
  330.         #type = struct.unpack("b", data[offset:offset+1])[0]
  331.        
  332.         if type == TYPE_NIL :
  333.             return None
  334.         elif type == TYPE_BOOLEAN :
  335.             return self.readBool(offset)
  336.    
  337.         elif type == TYPE_STRING:
  338.             return self.readLine(offset)
  339.        
  340.         elif type == TYPE_NUMBER:
  341.             return self.readFloat(offset)
  342.            
  343.         elif type == TABLE_BEGIN :
  344.             table = []
  345.             while True :
  346.                 type = self.peekType(self.bin[offset:offset+1])
  347.                 if type == TABLE_END :
  348.                     break
  349.    
  350.    
  351.                 datasKey = self.parseLua(offset)
  352.                 key = ''
  353.                 if datasKey != None :
  354.                     off, key = datasKey
  355.                     offset = off
  356.    
  357.                
  358.                 datasValue = self.parseLua(offset)
  359.                 value = ''
  360.                 if datasValue != None :
  361.                     off, value = datasValue
  362.                     offset =  off
  363.                     pair = (key, value)
  364.                     table.append(pair)
  365.    
  366.                 else :
  367.                     offset = offset + 1
  368.    
  369.            
  370.             return offset+1, table
  371.        
  372.         elif type == TABLE_END :
  373.             raise Exception("Error: unexpected end-of-table")
  374.    
  375.         else :
  376.             raise Exception("Unknown lua data")
  377.  
  378.     def readHeader(self):
  379.         self.offset, supcomVersion = self.readLine(self.offset)
  380.         self.offset = self.offset + 3
  381.  
  382.  
  383.         if (supcomVersion.startswith("Supreme Commander v1") == False) :
  384.             raise Exception("The file format of this replay is unknown")
  385.  
  386.         self.supcomVersion = supcomVersion
  387.  
  388.         self.offset, replayVersion = self.readLine(self.offset)
  389.         self.offset = self.offset + 1
  390.        
  391.  
  392.         if (replayVersion.startswith("Replay v1.9") == False) :
  393.             raise Exception("The file format of this replay is unknown")
  394.         self.replayVersion = replayVersion
  395.  
  396.  
  397.         self.offset, map = self.readLine(self.offset)
  398.         print map
  399.         self.offset = self.offset + 4
  400.        
  401.         self.offset, count = self.readInt(self.offset)
  402.        
  403.        
  404.         self.offset = self.offset + count
  405.        
  406.         self.offset, count = self.readInt(self.offset)
  407.         print count
  408.        
  409.         self.offset, scenario = self.parseLua(self.offset)
  410.         infos = replayInfos()
  411.        
  412.        
  413.         numSource = struct.unpack("b", self.bin[self.offset:self.offset+1])[0]
  414.         self.offset = self.offset + 1
  415.        
  416.         for i in range(numSource) :
  417.             self.offset, name = self.readLine(self.offset)
  418.             self.offset, val = self.readInt(self.offset)
  419.        
  420.        
  421.         cheatsEnabled = struct.unpack("b", self.bin[self.offset:self.offset+1])[0]
  422.         self.offset = self.offset + 1
  423.        
  424.         infos.setCheat(cheatsEnabled)
  425.        
  426.        
  427.         numArmies = struct.unpack("b", self.bin[self.offset:self.offset+1])[0]
  428.         self.offset = self.offset + 1
  429.        
  430.         armies = replayArmyContainer()
  431.        
  432.         for i in range(0,numArmies) :
  433.             self.offset, val = self.readInt(self.offset)
  434.        
  435.             self.offset, army = self.parseLua(self.offset)
  436.            
  437.             newArmy = replayArmy()
  438.             newArmy.populate(army)
  439.             if newArmy.isPlayer() :
  440.                 armies.add(newArmy)
  441.            
  442.            
  443.             b = struct.unpack("b", self.bin[self.offset:self.offset+1])[0]
  444.             self.offset = self.offset + 1
  445.             if b != -1 :
  446.                 #b = struct.unpack("b", self.bin[self.offset:self.offset+1])[0]
  447.                 self.offset = self.offset + 1
  448.                 #print b
  449.        
  450.         for army in armies :
  451.             self.players.append(army)
  452.        
  453.         self.offset, randomSeed = self.readInt(self.offset)
  454.         print "randomSeed", randomSeed
  455.  
  456.  
  457.     def setGameTime(self):
  458.         tick = 0
  459.         offset = self.offset
  460.         while offset < len(self.bin):
  461.             offset, message_op = self.readChar(offset)
  462.             offset, message_length = self.readShort(offset)
  463.             if message_op == 0:
  464.                 tick = tick+1
  465.        
  466.             #skip all the data we don't need to look at we're just looking for the time in this function.
  467.             offset = offset + message_length - 3
  468.        
  469.         return tick
  470.    
  471.    
  472.     def setPlayerLastTurn(self):
  473.         tick = 0
  474.         currentAction = 0
  475.         currentPlayer = 0
  476.         playerturn = 0
  477.         playerLastTurn = {}
  478.        
  479.         offset = self.offset
  480.         while offset < len(self.bin):
  481.             offset, message_op = self.readChar(offset)
  482.             offset, message_length = self.readShort(offset)
  483.             if message_op == 0:
  484.                 tick = tick + 1
  485.             elif message_op == 1:
  486.                 _, playerturn = self.readChar(offset)
  487.             elif message_op == 11:
  488.                 if currentAction != tick or currentPlayer != playerturn:
  489.                     currentAction = tick
  490.                     currentPlayer = playerturn
  491.                     playerLastTurn[playerturn]=tick
  492.             elif message_op == 12:
  493.                 playerLastTurn[playerturn]=tick
  494.             elif message_op == 13:
  495.                 playerLastTurn[playerturn]=tick                    
  496.             elif message_op == 19:
  497.                 if currentAction != tick or currentPlayer != playerturn:
  498.                     currentAction = tick
  499.                     currentPlayer = playerturn
  500.                     playerLastTurn[playerturn]=tick
  501.             elif message_op == 22:
  502.                 if currentAction != tick or currentPlayer != playerturn:
  503.                     currentAction = tick
  504.                     currentPlayer = playerturn
  505.                     playerLastTurn[playerturn]=tick                                        
  506.             #skip all the data we don't need to look at we're just looking for the time in this function.
  507.             offset = offset + message_length - 3
  508.        
  509.         return playerLastTurn
  510.  
  511.        
  512.    
  513.     def setDebugDesync(self):
  514.         tick = 0
  515.         currentAction = 0
  516.         currentPlayer = 0
  517.         playerturn = 0
  518.         playerLastTurn = {}
  519.         lastbeat = 0
  520.         beatChecksum = {}
  521.         debug = False
  522.         offset = self.offset
  523.         beatDesync = 11450
  524.         while offset < len(self.bin):
  525.             offset, message_op = self.readChar(offset)
  526.             offset, message_length = self.readShort(offset)
  527.            
  528.            
  529.             if lastbeat == beatDesync or lastbeat == beatDesync-50:
  530.  
  531.                 if message_op != 1 and message_op != 3 and message_op != 12 and message_op != 22:
  532.                     print message_op
  533.                 debug = True
  534.             else:
  535.                 debug = False
  536.             if message_op == 0:
  537.                
  538.                 _, tickToAdvance = self.readInt(offset)
  539.                 tick = tick + tickToAdvance
  540.  
  541.             elif message_op == 1:
  542.                 _, playerturn = self.readChar(offset)
  543.                 if debug:
  544.                     print "playerTurn", playerturn
  545.             elif message_op == 3:
  546.                 #print message_length
  547.                 '''CMDST_VerifyChecksum,
  548.                // MD5Digest - checksum
  549.                // uint32 - beat number'''
  550.                 fakeoffset = offset
  551.                 MD5Digest = ""
  552.                 "WARNING: Checksum for beat 1350 mismatched: 68711eb1013370f85ec772abbbf4ac1a (sim) != 45dcf9efa267331f691a87bd47acdb5d (BC_Blackheart)."
  553.                                                              
  554.                 for _ in range(16):
  555.  
  556.                     MD5Digest += (struct.unpack("s", self.bin[fakeoffset:fakeoffset+1])[0]).encode("hex")
  557.                     #MD5Digest =  MD5Digest + struct.unpack("B", self.bin[fakeoffset:fakeoffset+1])[0]
  558.                     fakeoffset = fakeoffset + 1  
  559.                 if debug:
  560.                     print MD5Digest
  561.                 _, beat = self.readInt(fakeoffset)
  562.                 lastbeat = beat
  563.  
  564.                 if not beat in beatChecksum:
  565.                     beatChecksum[beat] = []
  566.                 beatChecksum[beat].append(beat)
  567.                 if len(beatChecksum[beat]) == len(self.players):
  568.                     #print "beats", beatChecksum[beat]
  569.                     if len( set( beatChecksum[beat] ) ) != 1:
  570.                        
  571.                         print "error on beat", beat, "tick", tick
  572.  
  573.                
  574.             elif message_op == 11:
  575.                 if currentAction != tick or currentPlayer != playerturn:
  576.                     currentAction = tick
  577.                     currentPlayer = playerturn
  578.                     playerLastTurn[playerturn]=tick
  579.             elif message_op == 12:
  580.                 if debug:
  581.                     print "CMDST_IssueCommand for player", playerturn
  582.                    
  583.                     fakeoffset = offset
  584.                     fakeoffset, numUnits = self.readInt(fakeoffset)
  585.                     for i in range(numUnits):
  586.                         fakeoffset, entityId = self.readInt(fakeoffset)
  587.                        
  588.                     fakeoffset,commandId = self.readInt(fakeoffset)
  589.                     fakeoffset += 4
  590.                    
  591.                     fakeoffset, commandType = self.readChar(fakeoffset)
  592.                     fakeoffset += 4
  593.                    
  594.                     fakeoffset, STITarget = self.readChar(fakeoffset)
  595.                    
  596.                     print "command type", commandType
  597.                     if commandType == 7 or  commandType == 8 or commandType == 27:
  598.                         if STITarget == 0:
  599.                             fakeoffset += 6
  600.                         elif STITarget == 2:
  601.                             fakeoffset += 1 + 3 * 4 + 1 + 4
  602.                         unitBluePrint = ""
  603.                         for i in range(7):
  604.                             unitBluePrint =  unitBluePrint + struct.unpack("s", self.bin[fakeoffset:fakeoffset+1])[0]
  605.                             fakeoffset = fakeoffset + 1
  606.                         print unitBluePrint
  607.                    
  608.                
  609.                 if currentAction != tick or currentPlayer != playerturn:
  610.                    
  611.                     currentAction = tick
  612.                     currentPlayer = playerturn
  613.                     playerLastTurn[playerturn]=tick
  614.                     pass
  615. #                    if commandType == 5 :
  616. #                        print "UNITCOMMAND_BuildSiloTactical"
  617. #                    elif commandType == 6:
  618. #                        print "BuildSiloNuke"
  619. #                    elif commandType == 7:
  620. #                        print "BuildFactory"
  621. #                    elif commandType == 8:
  622. #                        print "BuildMobile"
  623. #                    elif commandType == 9:
  624. #                        print "BuildAssist"
  625. #                    elif commandType == 15:
  626. #                        print "Guard"
  627. #                    elif commandType == 16:
  628. #                        print "Patrol"
  629. #                    elif commandType == 19:
  630. #                        print "Reclaim"
  631. #                    elif commandType == 20:
  632. #                        print "Repair"
  633. #                    elif commandType == 21:
  634. #                        print "Capture"
  635. #                    elif commandType == 27:
  636. #                        print "Upgrade"
  637. #                    elif commandType == 28:
  638. #                        print "Script"
  639. #                    elif commandType == 29:
  640. #                        print "AssistCommander"
  641. #                    elif commandType == 32:
  642. #                        print "Sacrifice"                                                                        
  643. #                    elif commandType == 33:
  644. #                        print "Pause"
  645. #                    elif commandType == 38:
  646. #                        print "SpecialAction"                                                
  647.                 playerLastTurn[playerturn]=tick
  648.             elif message_op == 13:
  649.                 playerLastTurn[playerturn]=tick                    
  650.             elif message_op == 19:
  651.                 if currentAction != tick or currentPlayer != playerturn:
  652.                     currentAction = tick
  653.                     currentPlayer = playerturn
  654.                     playerLastTurn[playerturn]=tick
  655.             elif message_op == 22:
  656.                
  657.                 fakeoffset = offset
  658.                 fakeoffset, command = self.readLine(offset)
  659.                 fakeoffset, table = self.parseLua(fakeoffset)
  660.                 if debug:
  661.                     print command, table
  662.                 if currentAction != tick or currentPlayer != playerturn:
  663.                     currentAction = tick
  664.                     currentPlayer = playerturn
  665.                     playerLastTurn[playerturn]=tick                                        
  666.             #skip all the data we don't need to look at we're just looking for the time in this function.
  667.             offset = offset + message_length - 3
  668.        
  669.        
  670.         #print val
  671.  
  672.  
  673.     def setBuildOrder(self):
  674.         tick = 0
  675.         currentAction = 0
  676.         currentPlayer = 0
  677.         playerturn = 0
  678.         playerLastTurn = {}
  679.        
  680.         offset = self.offset
  681.         while offset < len(self.bin):
  682.             offset, message_op = self.readChar(offset)
  683.             offset, message_length = self.readShort(offset)
  684.             if message_op == 0:
  685.                 tick = tick + 1
  686.             elif message_op == 1:
  687.                 _, playerturn = self.readChar(offset)
  688.             elif message_op == 11:
  689.                 if currentAction != tick or currentPlayer != playerturn:
  690.                     currentAction = tick
  691.                     currentPlayer = playerturn
  692.                     playerLastTurn[playerturn]=tick
  693.             elif message_op == 12:
  694.                 fakeoffset = offset
  695.                 fakeoffset, numUnits = self.readInt(fakeoffset)
  696.                 for i in range(numUnits):
  697.                     fakeoffset, entityId = self.readInt(fakeoffset)
  698.                    
  699.                 fakeoffset,commandId = self.readInt(fakeoffset)
  700.                 fakeoffset += 4
  701.                
  702.                 fakeoffset, commandType = self.readChar(fakeoffset)
  703.                 fakeoffset += 4
  704.                
  705.                 fakeoffset, STITarget = self.readChar(fakeoffset)
  706.                
  707.                 if currentAction != tick or currentPlayer != playerturn:
  708.                    
  709.                     currentAction = tick
  710.                     currentPlayer = playerturn
  711.                     playerLastTurn[playerturn]=tick
  712.                     if commandType == 7 or  commandType == 8 or commandType == 27:
  713.                         if STITarget == 0:
  714.                             fakeoffset += 6
  715.                         elif STITarget == 2:
  716.                             fakeoffset += 1 + 3 * 4 + 1 + 4
  717.                         unitBluePrint = ""
  718.                         for i in range(7):
  719.                             unitBluePrint =  unitBluePrint + struct.unpack("s", self.bin[fakeoffset:fakeoffset+1])[0]
  720.                             fakeoffset = fakeoffset + 1
  721.                         print unitBluePrint
  722.  
  723.                                
  724.                        
  725.                 playerLastTurn[playerturn]=tick
  726.             elif message_op == 13:
  727.                 playerLastTurn[playerturn]=tick                    
  728.             elif message_op == 19:
  729.                 if currentAction != tick or currentPlayer != playerturn:
  730.                     currentAction = tick
  731.                     currentPlayer = playerturn
  732.                     playerLastTurn[playerturn]=tick
  733.             elif message_op == 22:
  734.  
  735.                 if currentAction != tick or currentPlayer != playerturn:
  736.                     currentAction = tick
  737.                     currentPlayer = playerturn
  738.                     playerLastTurn[playerturn]=tick                                        
  739.             #skip all the data we don't need to look at we're just looking for the time in this function.
  740.             offset = offset + message_length - 3        
  741.  
  742.  
  743. inFile = r'c:\Users\nozon\Downloads\1265754.fafreplay'
  744.  
  745.            
  746.  
  747.  
  748.  
  749. replay = replayParser(inFile)
  750. replay.readHeader()
  751. print "gametime", (float(replay.setGameTime()) /10.0) / 60.0, "minutes"
  752.  
  753. lastTurns= replay.setPlayerLastTurn()
  754. for l in lastTurns :
  755.     print replay.players[l], ((lastTurns[l] /10.0) / 60.0), "minutes"
  756. #
  757. replay.setBuildOrder()
  758. replay.setDebugDesync()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement