Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import sys
- import zipfile
- import time
- path_kits_zipname = 'objects_common_server.zip'
- path_mapserver_zipname = 'server.zip'
- path_content = 'content'
- path_levels = 'levels'
- path_kits = 'kits'
- path_gamemodes = 'gamemodes'
- gamemodes = [
- 'gpm_cq',
- 'gpm_skirmish',
- 'gpm_insurgency',
- 'gpm_coop',
- 'gpm_cnc',
- 'gpm_vehicles',
- 'gpm_objective',
- 'sp1',
- 'sp2',
- 'sp3',
- ]
- layers = [
- '16',
- '32',
- '64',
- '128',
- ]
- kits_list = []
- #maps_kits_details = {} # 'dirname' : {'gamemode':{'layer':{'templates: {'cpname_*: object'}, 'spawners' : {'cpname_*: object'}}}}
- def debug_data(maps_kits_details):
- fo = open('kits_topas.txt', 'w')
- for mapname in maps_kits_details:
- #print('checking map {} from {}'.format(mapname, maps_kits_details.keys()))
- for gamemode in maps_kits_details[mapname]:
- #print('checking gamemode {}'.format(gamemode))
- for layer in maps_kits_details[mapname][gamemode]:
- #print('checking layer {}'.format(layer))
- #print('--{}/{}/{}'.format(mapname, gamemode, layer))
- #print('maps_kits_details[{}][{}][{}] = \n{}\n\n'.format(mapname, gamemode, layer, maps_kits_details[mapname][gamemode][layer]))
- #print('maps_kits_details[mapname][gamemode][0] = \n{}'.format(maps_kits_details[mapname][gamemode][0]))
- if len(maps_kits_details[mapname][gamemode][layer].spawners) != 0:
- fo.write('--------------------------------------------------------------------------------\n')
- fo.write('{}[{}][{}]:\n\n'.format(mapname, gamemode, layer))
- for spawner in maps_kits_details[mapname][gamemode][layer].spawners:
- spawner_template_name = maps_kits_details[mapname][gamemode][layer].spawners[spawner].spawner_name
- spawner_position = maps_kits_details[mapname][gamemode][layer].spawners[spawner].position
- spawner_template = maps_kits_details[mapname][gamemode][layer].templates[spawner_template_name]#.spawner_object_template
- string_create = 'Object.create {}\nObject.absolutePosition {}/{}/{}'.format(spawner_template_name,*spawner_position)
- string_template = 'ObjectTemplate.setObjectTemplate {} {}'.format(spawner_template.spawner_team, spawner_template.spawner_object_template)
- print(string_create)
- print(string_template + '\n')
- fo.write(string_create + '\n')
- fo.write(string_template + '\n\n')
- fo.close()
- def set_maps_kits_details():
- maps_kits_details = {}
- for dirname, dirnames, filenames in os.walk(path_levels):
- if path_mapserver_zipname in filenames:
- map_details = get_maps_kits_data(os.path.join(dirname, path_mapserver_zipname))
- #print('checking {}'.format(os.path.join(dirname, path_mapserver_zipname)))
- levelname = dirname.split('\\')[-1]
- maps_kits_details[levelname] = {}
- maps_kits_details[levelname] = map_details
- print('parsed {}, len = ({})'.format(levelname, len(maps_kits_details)))
- #break
- return maps_kits_details
- def get_maps_kits_data(maparchive):
- class MapDetails:
- def __init__(self, templates, spawners):
- self.templates = templates
- self.spawners = spawners
- map_details = {}
- with zipfile.ZipFile(maparchive) as mapzip:
- filelist = mapzip.namelist()
- for filename in filelist:
- #print(os.path.join(mapzip, filename))
- if filename.split('/')[0].lower() == path_gamemodes and filename.split('.')[-1] == 'con' and filename.split('.')[0].split('/')[-1].lower() == 'gameplayobjects':
- with mapzip.open(filename, 'r') as gpofile:
- newlines = []
- for line in gpofile:
- newlines.append(line.decode("utf-8").strip())
- gpofile.close()
- #print(os.path.join(maparchive, filename))
- templates, spawners = get_map_kits_data(newlines)
- gamemode = filename.split('.')[0].split('/')[-3].lower()
- layer = filename.split('.')[0].split('/')[-2].lower()
- if gamemode in gamemodes and layer in layers:
- map_details[gamemode] = {}
- map_details[gamemode][layer] = MapDetails(templates, spawners)
- else:
- print('[{}][{}]not in shit!!!'.format(gamemode, layer))
- print('gamemodes = [')
- for g in gamemodes:
- print(' {}'.format(g))
- print(' ]')
- time.sleep(1)
- print(os.path.join(maparchive, filename))
- time.sleep(2)
- #mapzip.close()
- #sys.exit()
- mapzip.close()
- return map_details
- def get_map_kits_data(lines):
- spawner_templates = {}
- spawner_objects = {}
- active_object = [None]
- class ObjectSpawnerTemplate:
- def __init__(self, spawner_name, start):
- self.start = start
- self.spawner_name = spawner_name.replace('\n', '').replace('\r', '')
- self.spawner_object_template = None
- self.spawner_team = None
- self.active = False
- def set_data(self):
- if active_object[0] != None:
- active_object[0].active = False
- active_object[0] = self
- active_object[0].active = True
- line_id = self.start
- while self.active == True and len(lines) > line_id:
- line = lines[line_id]
- if line.lower().startswith('objecttemplate.setobjecttemplate'):
- spawner_template_parts = line.split(' ')
- self.spawner_object_template = spawner_template_parts[-1].replace('\n', '').replace('\r', '')
- self.spawner_team = spawner_template_parts[-2]
- self.active = False
- line_id += 1
- class ObjectTemplate:
- def __init__(self, spawner_name, start):
- self.start = start
- self.spawner_name = spawner_name.replace('\n', '').replace('\r', '')
- self.position = (None, None, None)
- self.active = False
- def set_data(self):
- if active_object[0] != None:
- active_object[0].active = False
- active_object[0] = self
- active_object[0].active = True
- line_id = self.start
- while self.active == True and len(lines) > line_id:
- line = lines[line_id]
- if line.lower().startswith('object.absoluteposition'):
- object_spawner_parts = line.replace('\n', '').replace('\r', '').split(' ')
- self.position = object_spawner_parts[-1].split('/')
- self.active = False
- line_id += 1
- counter = 0
- for line in lines:
- counter += 1
- #print(line)
- #time.sleep(0.5)
- line_parts = line.split(' ')
- if len(line_parts) > 2:
- if line_parts[0].lower() == 'objecttemplate.create':
- if line_parts[1].lower() == 'objectspawner':
- spawner_template = ObjectSpawnerTemplate(line_parts[2], counter)
- spawner_template.set_data()
- #print('[{}]{}'.format(counter, line))
- #print('[{}]ObjectTemplate.setObjectTemplate {} {}'.format(counter, spawner_template.spawner_team, spawner_template.spawner_object_template))
- #time.sleep(1)
- if spawner_template.spawner_object_template in kits_list:
- spawner_templates[spawner_template.spawner_name] = spawner_template
- #print('class template = "{}"'.format(spawner_template.spawner_object_template))
- counter = 0
- for line in lines:
- counter += 1
- line_parts = line.strip().split(' ')
- if len(line_parts) >= 2:
- #print(line_parts)
- #time.sleep(0.02)
- if line_parts[0].lower() == 'object.create':
- #print('spawning1 {}'.format(line_parts[1]))
- #print('len of templates = [{}]'.format(len(spawner_templates)))
- if line_parts[1] in spawner_templates.keys():
- #print('spawning2 {}'.format(line_parts[1]))
- #time.sleep(1)
- spawner = ObjectTemplate(line_parts[1], counter)
- spawner.set_data()
- spawner_objects[spawner.spawner_name] = spawner
- #print('[{}]{}'.format(counter, line))
- #print('[{}]Object.absolutePosition {}/{}/{}'.format(counter, *spawner.position))
- return (spawner_templates, spawner_objects)
- def set_kits_templates():
- with zipfile.ZipFile(os.path.join(path_content, path_kits_zipname)) as contentzip:
- filelist = contentzip.namelist()
- for filename in filelist:
- if filename.split('/')[0] == path_kits and filename.split('.')[-1] == 'con':
- with contentzip.open(filename, 'r') as kitfile:
- lines = kitfile.read().splitlines()
- kitfile.close()
- for line in lines:
- line = line.decode("utf-8")
- new_line = ' '.join(line.split(' ')[0:2])
- #print(new_line)
- if new_line == 'ObjectTemplate.create Kit':
- add_kit(line)
- #time.sleep(1)
- contentzip.close()
- print("Added {} kits to checklist".format(len(kits_list)))
- def add_kit(string):
- global kits_list
- kit_parts = string.split(' ')
- kit = kit_parts[-1]
- kits_list.append(kit)
- #if kit.startswith('meinsurgent'):
- # print("Added kit ['{}'] to list".format(kit))
- def main():
- set_kits_templates()
- dataset = set_maps_kits_details()
- debug_data(dataset)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement