Exemplo n.º 1
0
def convertToFullForm(compactForm, battleResultVersion):
    from SafeUnpickler import SafeUnpickler

    handled = 0
    import importlib
    battle_results_data = importlib.import_module('wotbr2jlib.battle_results_shared_' + str(battleResultVersion).zfill(2))

    if len(battle_results_data.VEH_FULL_RESULTS)==0:
        exitwitherror("Unsupported Battle Result Version: " + str(battleResultVersion))
    else:
        if battleResultVersion >= 18:

            arenaUniqueID, avatarResults, fullResultsList, pickled = compactForm
            fullResultsList = SafeUnpickler.loads(zlib.decompress(fullResultsList))
            avatarResults = SafeUnpickler.loads(zlib.decompress(avatarResults))
            personal = {}
            try:
                fullForm = {'arenaUniqueID': arenaUniqueID,
                'personal': personal,
                'common': {},
                'players': {},
                'vehicles': {},
                'avatars': {}}
                personal['avatar'] = avatarResults = battle_results_data.AVATAR_FULL_RESULTS.unpack(avatarResults)
                for vehTypeCompDescr, ownResults in fullResultsList.iteritems():
                    vehPersonal = personal[vehTypeCompDescr] = battle_results_data.VEH_FULL_RESULTS.unpack(ownResults)
                    vehPersonal['details'] = battle_results_data.VehicleInteractionDetails.fromPacked(vehPersonal['details']).toDict()
                    vehPersonal['isPrematureLeave'] = avatarResults['isPrematureLeave']
                    vehPersonal['fairplayViolations'] = avatarResults['fairplayViolations']
                    vehPersonal['club'] = avatarResults['club']
                    vehPersonal['enemyClub'] = avatarResults['enemyClub']

                commonAsList, playersAsList, vehiclesAsList, avatarsAsList = SafeUnpickler.loads(zlib.decompress(pickled))
                fullForm['common'] = battle_results_data.COMMON_RESULTS.unpack(commonAsList)
                for accountDBID, playerAsList in playersAsList.iteritems():
                    fullForm['players'][accountDBID] = battle_results_data.PLAYER_INFO.unpack(playerAsList)

                for accountDBID, avatarAsList in avatarsAsList.iteritems():
                    fullForm['avatars'][accountDBID] = battle_results_data.AVATAR_PUBLIC_RESULTS.unpack(avatarAsList)

                for vehicleID, vehiclesInfo in vehiclesAsList.iteritems():
                    fullForm['vehicles'][vehicleID] = []
                    for vehTypeCompDescr, vehicleInfo in vehiclesInfo.iteritems():
                        fullForm['vehicles'][vehicleID].append(battle_results_data.VEH_PUBLIC_RESULTS.unpack(vehicleInfo))
            except IndexError, i:
                return 0, {}
            except KeyError, i:
                return 0, {}
            except Exception, e:
                exitwitherror("Error occured while transforming Battle Result Version: " + str(battleResultVersion) + " Error: " + str(e))
Exemplo n.º 2
0
def pkt_credential(self, buff, clock):
    """extract data from header"""

    # skip unknown leading 10 bytes
    dat = buff[10:]
    size, = struct.unpack_from("B", dat)
    playerID = str(dat[1:1 + size])
    dat = dat[1 + size:]

    bin_data = "QIBBB"
    bin_data_size = struct.calcsize(bin_data)

    arenaUniqueID, arenaTypeID, bonusType, guiType, advancedlength = struct.unpack_from(
        bin_data, dat)
    dat = dat[bin_data_size:]

    if advancedlength == 255:
        bin_data_adv = "HB"
        bin_data_adv_size = struct.calcsize(bin_data_adv)
        advancedlength, tmp = struct.unpack_from(bin_data_adv, dat)
        dat = dat[bin_data_adv_size:]

    ext_data = {'battleLevel': 0}
    try:
        advanced_pickles = dat[:advancedlength]
        from SafeUnpickler import SafeUnpickler
        ext_data = SafeUnpickler.loads(advanced_pickles)
    except Exception, e:
        pass
Exemplo n.º 3
0
def pkt_credential(self, buff, clock):
    """extract data from header"""

    # skip unknown leading 10 bytes
    dat = buff[10:]
    size, = struct.unpack_from("B", dat)
    playerID = str(dat[1:1+size])
    dat = dat[1+size:]

    bin_data = "QIBBB"
    bin_data_size = struct.calcsize(bin_data)

    arenaUniqueID, arenaTypeID, bonusType, guiType, advancedlength = struct.unpack_from(bin_data, dat)
    dat = dat[bin_data_size:]

    if advancedlength==255:
        bin_data_adv = "HB"
        bin_data_adv_size = struct.calcsize(bin_data_adv)
        advancedlength, tmp = struct.unpack_from(bin_data_adv, dat)
        dat = dat[bin_data_adv_size:]

    ext_data = {'battleLevel': 0}
    try:
        advanced_pickles = dat[:advancedlength]
        from SafeUnpickler import SafeUnpickler
        ext_data = SafeUnpickler.loads(advanced_pickles)
    except Exception, e:
        pass
def process(file):
    try:
        from SafeUnpickler import SafeUnpickler
        legacyBattleResultVersion, battleResults = SafeUnpickler.load(file)
    except Exception, e:
        raise Exception(
            'Battle Result cannot be read (pickle could not be read) ' +
            e.message)
def convertToFullForm(compactForm, battleResultVersion): 
	from SafeUnpickler import SafeUnpickler
	
	handled = 0
	import importlib
	battle_results_data = importlib.import_module('battle_results_shared_' + str(battleResultVersion).zfill(2))

	if len(battle_results_data.VEH_FULL_RESULTS)==0:
		exitwitherror("Unsupported Battle Result Version: " + str(battleResultVersion))
	else:
		if battleResultVersion >= 15:  

			arenaUniqueID, fullResultsList, pickled, uniqueSubUrl = compactForm
			fullResultsList = SafeUnpickler.loads(zlib.decompress(fullResultsList))
			personal = {}
			try:
				fullForm = {'arenaUniqueID': arenaUniqueID,
					'personal': personal,
					'common': {},
					'players': {},
					'vehicles': {},
					'uniqueSubUrl': uniqueSubUrl}
				for vehTypeCompDescr, ownResults in fullResultsList.iteritems():
					vehPersonal = personal[vehTypeCompDescr] = battle_results_data.VEH_FULL_RESULTS.unpack(ownResults)
					
					vehPersonal['details'] = battle_results_data.VehicleInteractionDetails.fromPacked(vehPersonal['details']).toDict()
							
				commonAsList, playersAsList, vehiclesAsList = SafeUnpickler.loads(zlib.decompress(pickled))
				fullForm['common'] = battle_results_data.COMMON_RESULTS.unpack(commonAsList)
				
				for accountDBID, playerAsList in playersAsList.iteritems():
					fullForm['players'][accountDBID] = battle_results_data.PLAYER_INFO.unpack(playerAsList)

				for vehicleID, vehiclesInfo in vehiclesAsList.iteritems():
					fullForm['vehicles'][vehicleID] = []
					for vehTypeCompDescr, vehicleInfo in vehiclesInfo.iteritems():
						fullForm['vehicles'][vehicleID].append(battle_results_data.VEH_PUBLIC_RESULTS.unpack(vehicleInfo))
						
			except IndexError, i:
				return 0, {}
			except Exception, e: 
				exitwitherror("Error occured while transforming Battle Result Version: " + str(battleResultVersion) + " Error: " + str(e))
def main(): 
		import struct, json, time, sys, os, shutil, datetime 
		  
		parserversion = "0.9.1.0"
		
		  
		
		global numofkills, filename_source, filename_target, option_server, option_format 
		option_raw = 0
		option_format = 0
		option_server = 0
		option_frags = 1
		  
		  
		if len(sys.argv) == 1: 
		    usage() 
		    sys.exit(2) 
		
		for argument in sys.argv: 
		    if argument == "-r": 
		        option_raw = 1
		    elif argument == "-f": 
		        option_format = 1
		    elif argument == "-s": 
		        option_server = 1
		
		filename_source = str(sys.argv[1]) 
		
		printmessage('###### WoTBR2J ' + parserversion) 
		
		printmessage('Processing ' + filename_source) 
		  
		if option_server == 0: 
		    tanksdata = get_json_data("tanks.json") 
		    mapdata = get_json_data("maps.json") 
		
		
		if not os.path.exists(filename_source) or not os.path.isfile(filename_source) or not os.access(filename_source, os.R_OK): 
		    exitwitherror('Battle Result does not exists!') 
		    sys.exit(1) 
		
		filename_target = os.path.splitext(filename_source)[0] 
		filename_target = filename_target + '.json'
		
		cachefile = open(filename_source, 'rb') 
		          
		try: 
			from SafeUnpickler import SafeUnpickler
			battleresultversion, battleResults = SafeUnpickler.load(cachefile) 
		except Exception, e: 
		    exitwitherror('Battle Result cannot be read (pickle could not be read) ' + e.message) 
		    sys.exit(1) 
Exemplo n.º 7
0
def main():

    import struct, json, time, sys, os, shutil, datetime

    global filename_source, filename_target, option_server, option_format, parser

    option_raw = 0
    option_format = 0
    option_server = 0
    option_frags = 1

    if len(sys.argv) == 1:
        usage()
        sys.exit(2)

    for argument in sys.argv:
        if argument == "-r":
            option_raw = 1
        elif argument == "-f":
            option_format = 1
        elif argument == "-s":
            option_server = 1

    filename_source = str(sys.argv[1])

    printmessage("###### WoTBR2J " + parser["version"], 0)

    printmessage("Processing " + filename_source, 0)

    filename_target = os.path.splitext(filename_source)[0]
    filename_target = filename_target + ".json"

    if (
        not os.path.exists(filename_source)
        or not os.path.isfile(filename_source)
        or not os.access(filename_source, os.R_OK)
    ):
        exitwitherror("Battle Result does not exists!")

    cachefile = open(filename_source, "rb")

    try:
        from SafeUnpickler import SafeUnpickler

        legacyBattleResultVersion, battleResults = SafeUnpickler.load(cachefile)
    except Exception, e:
        exitwitherror("Battle Result cannot be read (pickle could not be read) " + e.message)
Exemplo n.º 8
0
def main():

    import struct, json, time, sys, os, shutil, datetime
    global filename_source, filename_target, option_server, option_format, parser

    option_raw = 0
    option_format = 0
    option_server = 0
    option_frags = 1

    if len(sys.argv) == 1:
        usage()
        sys.exit(2)

    for argument in sys.argv:
        if argument == "-r":
            option_raw = 1
        elif argument == "-f":
            option_format = 1
        elif argument == "-s":
            option_server = 1

    filename_source = str(sys.argv[1])

    printmessage('###### WoTBR2J ' + parser['version'], 0)

    printmessage('Processing ' + filename_source, 0)

    filename_target = os.path.splitext(filename_source)[0]
    filename_target = filename_target + '.json'

    if not os.path.exists(filename_source) or not os.path.isfile(
            filename_source) or not os.access(filename_source, os.R_OK):
        exitwitherror('Battle Result does not exists!')

    cachefile = open(filename_source, 'rb')

    try:
        from SafeUnpickler import SafeUnpickler
        legacyBattleResultVersion, battleResults = SafeUnpickler.load(
            cachefile)
    except Exception, e:
        exitwitherror(
            'Battle Result cannot be read (pickle could not be read) ' +
            e.message)
                        fullForm['vehicles'][vehicleID].append(
                            battle_results_data.VEH_PUBLIC_RESULTS.unpack(
                                vehicleInfo))
            except IndexError, i:
                return 0, {}
            except KeyError, i:
                return 0, {}
            except Exception, e:
                exitwitherror(
                    "Error occured while transforming Battle Result Version: "
                    + str(battleResultVersion) + " Error: " + str(e))

        if battleResultVersion >= 17:

            arenaUniqueID, avatarResults, fullResultsList, pickled = compactForm
            fullResultsList = SafeUnpickler.loads(
                zlib.decompress(fullResultsList))
            avatarResults = SafeUnpickler.loads(zlib.decompress(avatarResults))
            personal = {}
            try:
                fullForm = {
                    'arenaUniqueID': arenaUniqueID,
                    'personal': personal,
                    'common': {},
                    'players': {},
                    'vehicles': {},
                    'avatars': {}
                }
                personal[
                    'avatar'] = avatarResults = battle_results_data.AVATAR_FULL_RESULTS.unpack(
                        avatarResults)
                for vehTypeCompDescr, ownResults in fullResultsList.iteritems(
Exemplo n.º 10
0
def main():

    import struct, json, time, sys, os, shutil, datetime, base64

    parserversion = "0.9.19.1"

    global rawdata, tupledata, data, structures, numoffrags
    global filename_source, filename_target
    global option_server, option_format, option_tanks

    filename_source = ""
    option_raw = 0
    option_format = 0
    option_server = 0
    option_frags = 1
    option_tanks = 0

    for argument in sys.argv[1:]:
        if argument == "-s":
            option_server = 1
            #print '-- SERVER mode enabled'
        elif argument == "-r":
            option_raw = 1
            #print '-- RAW mode enabled'
        elif argument == "-f":
            option_format = 1
            #print '-- FORMAT mode enabled'
        elif argument == "-k":
            option_frags = 0
            #print '-- FRAGS will be excluded'
        elif argument == "-t":
            option_tanks = 1
            #print '-- TANK info will be included'
        else:
            # dossier file, if more than one get only first
            if filename_source == '' and os.path.isfile(argument):
                filename_source = argument

    if filename_source == "":
        usage()
        sys.exit(2)

    printmessage('############################################')
    printmessage('###### WoTDC2J ' + parserversion)

    printmessage('Processing ' + filename_source)

    if not os.path.exists(filename_source) or not os.path.isfile(
            filename_source) or not os.access(filename_source, os.R_OK):
        catch_fatal('Dossier file does not exists')
        sys.exit(1)

    if os.path.getsize(filename_source) == 0:
        catch_fatal('Dossier file size is zero')
        sys.exit(1)

    filename_target = os.path.splitext(filename_source)[0]
    filename_target = filename_target + '.json'

    if os.path.exists(filename_target) and os.path.isfile(
            filename_target) and os.access(filename_target, os.R_OK):
        try:
            os.remove(filename_target)
        except:
            catch_fatal('Cannot remove target file ' + filename_target)

    cachefile = open(filename_source, 'rb')

    try:
        from SafeUnpickler import SafeUnpickler
        dossierversion, dossierCache = SafeUnpickler.load(cachefile)
    except Exception, e:
        exitwitherror('Dossier cannot be read (pickle could not be read) ' +
                      e.message)
Exemplo n.º 11
0
def extract_advanced(fn):
	advanced = dict()
	with open(fn, 'rb') as f:

		f.seek(12)
		versionlength = struct.unpack("B",f.read(1))[0]
	
		if not is_supported_replay(f):
			advanced['valid'] = 0
			printmessage('Unsupported replay: Versionlength: ' + str(versionlength))
			return advanced

		f.read(3)
	
		advanced['replay_version'] = f.read(versionlength)
		advanced['replay_version'] = advanced['replay_version'].replace(', ', '.').strip()
		advanced['replay_version'] = advanced['replay_version'].replace('. ', '.').strip()
		advanced['replay_version'] = advanced['replay_version'].replace(' ', '.').strip()

		f.seek(51 + versionlength)	
		playernamelength = struct.unpack("B",f.read(1))[0]

		advanced['playername'] = f.read(playernamelength)
		advanced['arenaUniqueID'] = struct.unpack("Q",f.read(8))[0]
		advanced['arenaCreateTime'] = advanced['arenaUniqueID'] & 4294967295L
		
		advanced['arenaTypeID'] = struct.unpack("I",f.read(4))[0]
		advanced['gameplayID'] = advanced['arenaTypeID'] >> 16
		advanced['arenaTypeID'] = advanced['arenaTypeID'] & 32767
		
		advanced['bonusType'] = struct.unpack("B",f.read(1))[0]
		advanced['guiType'] = struct.unpack("B",f.read(1))[0]
	
		
		advanced['more'] = dict()
		advancedlength = struct.unpack("B",f.read(1))[0]

		if advancedlength==255:
			advancedlength = struct.unpack("H",f.read(2))[0]
			f.read(1)

		try:
			advanced_pickles = f.read(advancedlength)
			from SafeUnpickler import SafeUnpickler
			advanced['more'] = SafeUnpickler.loads(advanced_pickles)	
		except Exception, e:
			printmessage('cannot load advanced pickle: ' + e.message)
			printmessage('Position: ' + str(f.tell()) + ", Length: " + str(advancedlength))

	
		f.seek(f.tell()+29)
		
		advancedlength = struct.unpack("B",f.read(1))[0]

		if advancedlength==255:
			advancedlength = struct.unpack("H",f.read(2))[0]
			f.read(1)
			
		#try:
		rosters = []
		try:
			advanced_pickles = f.read(advancedlength)
			from SafeUnpickler import SafeUnpickler
			rosters = SafeUnpickler.loads(advanced_pickles)		
		except Exception, e:
			printmessage('cannot load roster pickle: ' + e.message)
			printmessage('Position: ' + str(f.tell()) + ", Length: " + str(advancedlength))
Exemplo n.º 12
0
					except Exception, e:
						printmessage("Error with JSON: " + e.message)
					
					br_block = br_json_list[0]

					if len(br_json_list) > 0:
						result_blocks['datablock_1']['vehicles'] = br_json_list[1]

					if len(br_json_list) > 1:
						result_blocks['datablock_1']['kills'] = br_json_list[2]

				else:

					try:
						from SafeUnpickler import SafeUnpickler
						br_block = SafeUnpickler.loads(myblock)				
					except Exception, e:
						printmessage("Error with unpickling myblock: " + e.message)
					
				if 'vehicles' in br_block:
					for key, value in br_block['vehicles'].items():
						
						if br_block['vehicles'][key]['typeCompDescr'] > 0:
							br_block['vehicles'][key]['tankID'] = br_block['vehicles'][key]['typeCompDescr'] >> 8 & 65535
							br_block['vehicles'][key]['countryID'] = br_block['vehicles'][key]['typeCompDescr'] >> 4 & 15
						
						if 'details' in br_block['vehicles'][key]:
							del br_block['vehicles'][key]['details']
					
						
						#br_block['vehicles'][key]['details'] = decode_details(value['details'])
			fullForm = dict()
			try:
				fullForm = {'arenaUniqueID': compactForm[0], 
				 'personal': listToDict(battle_results_data.VEH_FULL_RESULTS, compactForm[1]), 
				 'common': {}, 
				 'players': {}, 
				 'vehicles': {}}

			except Exception, e: 
				exitwitherror("Error occured while transforming Battle Result Version: " + str(battleResultVersion) + " Error: " + str(e))
		
			if not 'personal' in fullForm:
				return fullForm
				  
			try:
				commonAsList, playersAsList, vehiclesAsList = SafeUnpickler.loads(compactForm[2]) 
			except Exception, e: 
				exitwitherror("Error occured while transforming Battle Result Version: " + str(battleResultVersion) + " Error: " + str(e))
			
			fullForm['common'] = listToDict(battle_results_data.COMMON_RESULTS, commonAsList) 
			
			for accountDBID, playerAsList in playersAsList.iteritems(): 
				fullForm['players'][accountDBID] = listToDict(battle_results_data.PLAYER_INFO, playerAsList) 
			  
			for vehicleID, vehicleAsList in vehiclesAsList.iteritems(): 
				fullForm['vehicles'][vehicleID] = listToDict(battle_results_data.VEH_PUBLIC_RESULTS, vehicleAsList)
	  
	return 1, fullForm 

def handleDetailsCrits(details):
Exemplo n.º 14
0
                for vehicleID, vehiclesInfo in vehiclesAsList.iteritems():
                    fullForm['vehicles'][vehicleID] = []
                    for vehTypeCompDescr, vehicleInfo in vehiclesInfo.iteritems():
                        fullForm['vehicles'][vehicleID].append(battle_results_data.VEH_PUBLIC_RESULTS.unpack(vehicleInfo))
            except IndexError, i:
                return 0, {}
            except KeyError, i:
                return 0, {}
            except Exception, e:
                exitwitherror("Error occured while transforming Battle Result Version: " + str(battleResultVersion) + " Error: " + str(e))

        elif battleResultVersion >= 18:

            arenaUniqueID, avatarResults, fullResultsList, pickled = compactForm
            fullResultsList = SafeUnpickler.loads(zlib.decompress(fullResultsList))
            avatarResults = SafeUnpickler.loads(zlib.decompress(avatarResults))
            personal = {}
            try:
                fullForm = {'arenaUniqueID': arenaUniqueID,
                'personal': personal,
                'common': {},
                'players': {},
                'vehicles': {},
                'avatars': {}}
                personal['avatar'] = avatarResults = battle_results_data.AVATAR_FULL_RESULTS.unpack(avatarResults)
                for vehTypeCompDescr, ownResults in fullResultsList.iteritems():
                    vehPersonal = personal[vehTypeCompDescr] = battle_results_data.VEH_FULL_RESULTS.unpack(ownResults)
                    vehPersonal['details'] = battle_results_data.VehicleInteractionDetails.fromPacked(vehPersonal['details']).toDict()
                    vehPersonal['isPrematureLeave'] = avatarResults['isPrematureLeave']
                    vehPersonal['fairplayViolations'] = avatarResults['fairplayViolations']
Exemplo n.º 15
0
                                br_block['personal'][
                                    vehTypeCompDescr] = ownResults

                if 'datablock_1' in result_blocks:
                    if len(br_json_list) > 0:
                        result_blocks['datablock_1'][
                            'vehicles'] = br_json_list[1]

                    if len(br_json_list) > 1:
                        result_blocks['datablock_1']['kills'] = br_json_list[2]

            else:

                try:
                    from SafeUnpickler import SafeUnpickler
                    br_block = SafeUnpickler.loads(myblock)
                    br_block['parser'] = dict()
                    br_block['parser']['battleResultVersion'] = 14
                except Exception, e:
                    printmessage("Error with unpickling myblock: " + e.message)

            if int(br_block['parser']['battleResultVersion']) < 15:
                if 'personal' in br_block:
                    br_block['personal']['details'] = decode_details(
                        br_block['personal']['details'])
                    if 'vehicles' in br_block:
                        for key, value in br_block['vehicles'].items():
                            if 'details' in br_block['vehicles'][key]:
                                del br_block['vehicles'][key]['details']

            result_blocks['datablock_battle_result'] = br_block
Exemplo n.º 16
0
	                        destroyedDevicesList.append(VEHICLE_DEVICE_TYPE_NAMES[shift]) 
	                  
	                for shift in range(len(VEHICLE_TANKMAN_TYPE_NAMES)): 
	                    if 1 << shift & destroyedTankmen: 
	                        critsCount += 1
	                        destroyedTankmenList.append(VEHICLE_TANKMAN_TYPE_NAMES[shift]) 
	  
	                fullForm['personal']['details'][vehicleid]['critsCount'] = critsCount 
	                fullForm['personal']['details'][vehicleid]['critsDestroyedTankmenList'] = destroyedTankmenList 
	                fullForm['personal']['details'][vehicleid]['critsCriticalDevicesList'] = criticalDevicesList 
	                fullForm['personal']['details'][vehicleid]['critsDestroyedDevicesList'] = destroyedDevicesList 
	
	      
	      
	from SafeUnpickler import SafeUnpickler
	commonAsList, playersAsList, vehiclesAsList = SafeUnpickler.loads(compactForm[2]) 
	fullForm['common'] = listToDict(COMMON_RESULTS, commonAsList) 
	for accountDBID, playerAsList in playersAsList.iteritems(): 
	    fullForm['players'][accountDBID] = listToDict(PLAYER_INFO, playerAsList) 
	  
	for vehicleID, vehicleAsList in vehiclesAsList.iteritems(): 
	    fullForm['vehicles'][vehicleID] = listToDict(VEH_PUBLIC_RESULTS, vehicleAsList) 
	    fullForm['vehicles'][vehicleID] = keepCompatibility(fullForm['vehicles'][vehicleID])
	  
	return fullForm 
  
  
  
############################################################################################################################ 
def keepCompatibility(structureddata):
Exemplo n.º 17
0
def main():
	
	import struct, json, time, sys, os, shutil, datetime, base64

	parserversion = "0.9.18.0"
	
	global rawdata, tupledata, data, structures, numoffrags
	global filename_source, filename_target
	global option_server, option_format, option_tanks
	
	filename_source = ""
	option_raw = 0
	option_format = 0
	option_server = 0
	option_frags = 1
	option_tanks = 0
	
	for argument in sys.argv:
		if argument == "-s":
			option_server = 1
			#print '-- SERVER mode enabled'
		elif argument == "-r":
			option_raw = 1
			#print '-- RAW mode enabled'
		elif argument == "-f":
			option_format = 1
			#print '-- FORMAT mode enabled'
		elif argument == "-k":
			option_frags = 0
			#print '-- FRAGS will be excluded'
		elif argument == "-t":
			option_tanks = 1
			#print '-- TANK info will be included'

	filename_source = sys.argv[1]
	
	if filename_source == "":
		usage()
		sys.exit(2)
		
	printmessage('############################################')
	printmessage('###### WoTDC2J ' + parserversion)
	

	printmessage('Processing ' + filename_source)
	

	if not os.path.exists(filename_source) or not os.path.isfile(filename_source) or not os.access(filename_source, os.R_OK):
		catch_fatal('Dossier file does not exists')
		sys.exit(1)

	if os.path.getsize(filename_source) == 0:
		catch_fatal('Dossier file size is zero')
		sys.exit(1)
		
	filename_target = os.path.splitext(filename_source)[0]
	filename_target = filename_target + '.json'

	if os.path.exists(filename_target) and os.path.isfile(filename_target) and os.access(filename_target, os.R_OK):
		try:
			os.remove(filename_target)
		except:
			catch_fatal('Cannot remove target file ' + filename_target)

			
	cachefile = open(filename_source, 'rb')

	try:
		from SafeUnpickler import SafeUnpickler
		dossierversion, dossierCache = SafeUnpickler.load(cachefile)
	except Exception, e:
		exitwitherror('Dossier cannot be read (pickle could not be read) ' + e.message)
Exemplo n.º 18
0
def extract_advanced(fn):
    advanced = dict()
    with open(fn, 'rb') as f:

        f.seek(12)
        versionlength = struct.unpack("B", f.read(1))[0]

        if not is_supported_replay(f):
            advanced['valid'] = 0
            printmessage('Unsupported replay: Versionlength: ' +
                         str(versionlength))
            return advanced

        f.read(3)

        advanced['replay_version'] = f.read(versionlength)
        advanced['replay_version'] = advanced['replay_version'].replace(
            ', ', '.').strip()
        advanced['replay_version'] = advanced['replay_version'].replace(
            '. ', '.').strip()
        advanced['replay_version'] = advanced['replay_version'].replace(
            ' ', '.').strip()

        f.seek(51 + versionlength)
        playernamelength = struct.unpack("B", f.read(1))[0]

        advanced['playername'] = f.read(playernamelength)
        advanced['arenaUniqueID'] = struct.unpack("Q", f.read(8))[0]
        advanced['arenaCreateTime'] = advanced['arenaUniqueID'] & 4294967295L

        advanced['arenaTypeID'] = struct.unpack("I", f.read(4))[0]
        advanced['gameplayID'] = advanced['arenaTypeID'] >> 16
        advanced['arenaTypeID'] = advanced['arenaTypeID'] & 32767

        advanced['bonusType'] = struct.unpack("B", f.read(1))[0]
        advanced['guiType'] = struct.unpack("B", f.read(1))[0]

        advanced['more'] = dict()
        advancedlength = struct.unpack("B", f.read(1))[0]

        if advancedlength == 255:
            advancedlength = struct.unpack("H", f.read(2))[0]
            f.read(1)

        try:
            advanced_pickles = f.read(advancedlength)
            from SafeUnpickler import SafeUnpickler
            advanced['more'] = SafeUnpickler.loads(advanced_pickles)
        except Exception, e:
            printmessage('cannot load advanced pickle: ' + e.message)
            printmessage('Position: ' + str(f.tell()) + ", Length: " +
                         str(advancedlength))

        f.seek(f.tell() + 29)

        advancedlength = struct.unpack("B", f.read(1))[0]

        if advancedlength == 255:
            advancedlength = struct.unpack("H", f.read(2))[0]
            f.read(1)

        #try:
        rosters = []
        try:
            advanced_pickles = f.read(advancedlength)
            from SafeUnpickler import SafeUnpickler
            rosters = SafeUnpickler.loads(advanced_pickles)
        except Exception, e:
            printmessage('cannot load roster pickle: ' + e.message)
            printmessage('Position: ' + str(f.tell()) + ", Length: " +
                         str(advancedlength))
Exemplo n.º 19
0
def process(file):
    try:
        from SafeUnpickler import SafeUnpickler
        legacyBattleResultVersion, battleResults = SafeUnpickler.load(file)
    except Exception, e:
        raise Exception('Battle Result cannot be read (pickle could not be read) ' + e.message)
Exemplo n.º 20
0
def convertToFullForm(compactForm, battleResultVersion):
    from SafeUnpickler import SafeUnpickler

    handled = 0
    import importlib
    battle_results_data = importlib.import_module(
        'battle_results_shared_' + str(battleResultVersion).zfill(2))

    if len(battle_results_data.VEH_FULL_RESULTS) == 0:
        exitwitherror("Unsupported Battle Result Version: " +
                      str(battleResultVersion))
    else:
        if battleResultVersion >= 24:

            arenaUniqueID, avatarResults, fullResultsList, pickled = compactForm
            fullResultsList = SafeUnpickler.loads(
                zlib.decompress(fullResultsList))
            avatarResults = SafeUnpickler.loads(zlib.decompress(avatarResults))
            personal = {}
            fullForm = {
                'arenaUniqueID': arenaUniqueID,
                'personal': personal,
                'common': {},
                'players': {},
                'vehicles': {},
                'avatars': {}
            }
            personal[
                'avatar'] = avatarResults = battle_results_data.AVATAR_FULL_RESULTS.unpack(
                    avatarResults)
            for vehTypeCompDescr, ownResults in fullResultsList.iteritems():
                ownResults[0] = 1226189367  # Override checksum
                vehPersonal = personal[
                    vehTypeCompDescr] = battle_results_data.VEH_FULL_RESULTS.unpack(
                        ownResults)
                if vehPersonal is None:
                    continue
                vehPersonal[
                    'details'] = battle_results_data.VehicleInteractionDetails.fromPacked(
                        vehPersonal['details']).toDict()

            commonAsList, playersAsList, vehiclesAsList, avatarsAsList = SafeUnpickler.loads(
                zlib.decompress(pickled))
            fullForm['common'] = battle_results_data.COMMON_RESULTS.unpack(
                commonAsList)
            for accountDBID, playerAsList in playersAsList.iteritems():
                fullForm['players'][
                    accountDBID] = battle_results_data.PLAYER_INFO.unpack(
                        playerAsList)

            for accountDBID, avatarAsList in avatarsAsList.iteritems():
                fullForm['avatars'][
                    accountDBID] = battle_results_data.AVATAR_PUBLIC_RESULTS.unpack(
                        avatarAsList)

            for vehicleID, vehiclesInfo in vehiclesAsList.iteritems():
                fullForm['vehicles'][vehicleID] = []
                for vehTypeCompDescr, vehicleInfo in vehiclesInfo.iteritems():
                    vehicleInfo[0] = 63936846  # Override checksum
                    fullForm['vehicles'][vehicleID].append(
                        battle_results_data.VEH_PUBLIC_RESULTS.unpack(
                            vehicleInfo))

        elif battleResultVersion >= 19:

            arenaUniqueID, avatarResults, fullResultsList, pickled = compactForm
            fullResultsList = SafeUnpickler.loads(
                zlib.decompress(fullResultsList))
            avatarResults = SafeUnpickler.loads(zlib.decompress(avatarResults))
            personal = {}
            try:
                fullForm = {
                    'arenaUniqueID': arenaUniqueID,
                    'personal': personal,
                    'common': {},
                    'players': {},
                    'vehicles': {},
                    'avatars': {}
                }
                personal[
                    'avatar'] = avatarResults = battle_results_data.AVATAR_FULL_RESULTS.unpack(
                        avatarResults)
                for vehTypeCompDescr, ownResults in fullResultsList.iteritems(
                ):
                    vehPersonal = personal[
                        vehTypeCompDescr] = battle_results_data.VEH_FULL_RESULTS.unpack(
                            ownResults)
                    if type(vehPersonal) is dict:
                        try:
                            vehPersonal[
                                'details'] = battle_results_data.VehicleInteractionDetails.fromPacked(
                                    vehPersonal['details']).toDict()
                        except Exception:
                            pass
                        vehPersonal['isPrematureLeave'] = avatarResults[
                            'isPrematureLeave']
                        vehPersonal['fairplayViolations'] = avatarResults[
                            'fairplayViolations']
                        vehPersonal['club'] = avatarResults['club']
                        vehPersonal['enemyClub'] = avatarResults['enemyClub']

                commonAsList, playersAsList, vehiclesAsList, avatarsAsList = SafeUnpickler.loads(
                    zlib.decompress(pickled))
                fullForm['common'] = battle_results_data.COMMON_RESULTS.unpack(
                    commonAsList)
                for accountDBID, playerAsList in playersAsList.iteritems():
                    fullForm['players'][
                        accountDBID] = battle_results_data.PLAYER_INFO.unpack(
                            playerAsList)

                for accountDBID, avatarAsList in avatarsAsList.iteritems():
                    fullForm['avatars'][
                        accountDBID] = battle_results_data.AVATAR_PUBLIC_RESULTS.unpack(
                            avatarAsList)

                for vehicleID, vehiclesInfo in vehiclesAsList.iteritems():
                    fullForm['vehicles'][vehicleID] = []
                    for vehTypeCompDescr, vehicleInfo in vehiclesInfo.iteritems(
                    ):
                        fullForm['vehicles'][vehicleID].append(
                            battle_results_data.VEH_PUBLIC_RESULTS.unpack(
                                vehicleInfo))
            except IndexError, i:
                return 0, {}
            except KeyError, i:
                return 0, {}
            except Exception, e:
                exitwitherror(
                    "Error occured while transforming Battle Result Version: "
                    + str(battleResultVersion) + " Error: " + str(e))