This commit is contained in:
Евгений Храмов 2023-05-14 14:54:35 +03:00
parent dea8d657b7
commit b11da8d1d0

96
hlna.py

@ -382,61 +382,59 @@ def modextract(id_mod, id_game_workshop):
print_line(dirnames)
for dname in dirnames:
os.makedirs(os.path.join(modextractdir, os.path.relpath(os.path.join(dirpath, dname), mod_steam_workshop)), exist_ok=True)
print_line(filenames)
print_line(dirnames)
for fname in filenames:
if not os.path.isfile(os.path.join(mod_steam_workshop, fname)) and not os.path.isfile(os.path.join(mod_steam_workshop, fname + ".z")):
os.unlink(os.path.join(modextractdir, fname))
for dname in dirnames:
if not os.path.isdir(os.path.join(mod_steam_workshop, dname)):
shutil.rmtree(os.path.join(modextractdir, os.path.relpath(os.path.join(dirpath, dname), mod_steam_workshop)))
for fname in filenames:
if not os.path.isfile(os.path.join(mod_steam_workshop, fname)) and not os.path.isfile(os.path.join(mod_steam_workshop, fname + ".z")):
os.unlink(os.path.join(modextractdir, fname))
for dname in dirnames:
if not os.path.isdir(os.path.join(mod_steam_workshop, dname)):
shutil.rmtree(os.path.join(modextractdir, os.path.relpath(os.path.join(dirpath, dname), mod_steam_workshop)))
for root, dirs, files in os.walk(mod_steam_workshop):
for name in files:
if not (name.endswith(".z") or name.endswith(".z.uncompressed_size")):
srcfile = os.path.join(root, name)
dstfile = os.path.join(modextractdir, os.path.relpath(srcfile, mod_steam_workshop))
if not os.path.isfile(dstfile) or os.path.getmtime(srcfile) > os.path.getmtime(dstfile):
shutil.copy2(srcfile, dstfile)
for root, dirs, files in os.walk(mod_steam_workshop):
for name in files:
if not (name.endswith(".z") or name.endswith(".z.uncompressed_size")):
srcfile = os.path.join(root, name)
dstfile = os.path.join(modextractdir, os.path.relpath(srcfile, mod_steam_workshop))
if not os.path.isfile(dstfile) or os.path.getmtime(srcfile) > os.path.getmtime(dstfile):
shutil.copy2(srcfile, dstfile)
modname = subprocess.check_output(['curl', '-s', 'https://steamcommunity.com/sharedfiles/filedetails/?id={}'.format(id_mod)]).decode('utf-8')
modname = re.search(r'<div class="workshopItemTitle">(.+)</div>', modname)
modname = modname and modname.group(1)
modname = subprocess.check_output(['curl', '-s', 'https://steamcommunity.com/sharedfiles/filedetails/?id={}'.format(id_mod)]).decode('utf-8')
modname = re.search(r'<div class="workshopItemTitle">(.+)</div>', modname)
modname = modname and modname.group(1)
if os.path.isfile("{}/.mod".format(modextractdir)):
os.remove("{}/.mod".format(modextractdir))
if os.path.isfile("{}/.mod".format(modextractdir)):
os.remove("{}/.mod".format(modextractdir))
modfile_bytes = b''
with open(os.path.join(modextractdir, 'mod.info'), 'rb') as f:
data = f.read()
mapnamelen = struct.unpack_from('<L', data, offset=0)
mapnamelen = mapnamelen[0]
mapname = str(data[4:mapnamelen + 3], 'utf-8')
nummaps = struct.unpack_from('<L', data, offset=mapnamelen + 4)
nummaps = nummaps[0]
pos = mapnamelen + 8
modname = (modname + mapname + "\x00").encode('utf-8')
modnamelen = len(modname)
modpath = ("../../../" + "ShooterGame" + "/Content/Mods/" + id_mod + "\x00").encode('utf-8')
modpathlen = len(modpath)
modfile_bytes += struct.pack('<LLL{}sL{}sL'.format(modnamelen, modpathlen),
int(id_mod), 0, modnamelen, modname, modpathlen, modpath, nummaps)
for _ in range(nummaps):
mapfilelen = struct.unpack_from('<L', data, offset=pos)
mapfilelen = mapfilelen[0]
mapfile = data[mapnamelen + 12:mapnamelen + 12 + mapfilelen]
modfile_bytes += struct.pack('<L{}s'.format(mapfilelen), mapfilelen, mapfile)
pos = pos + 4 + mapfilelen
modfile_bytes += b'\x33\xFF\x22\xFF\x02\x00\x00\x00\x01'
modfile_bytes = b''
with open(os.path.join(modextractdir, 'mod.info'), 'rb') as f:
data = f.read()
mapnamelen = struct.unpack_from('<L', data, offset=0)
mapnamelen = mapnamelen[0]
mapname = str(data[4:mapnamelen + 3], 'utf-8')
nummaps = struct.unpack_from('<L', data, offset=mapnamelen + 4)
nummaps = nummaps[0]
pos = mapnamelen + 8
modname = (modname + mapname + "\x00").encode('utf-8')
modnamelen = len(modname)
modpath = ("../../../" + "ShooterGame" + "/Content/Mods/" + id_mod + "\x00").encode('utf-8')
modpathlen = len(modpath)
modfile_bytes += struct.pack('<LLL{}sL{}sL'.format(modnamelen, modpathlen),
int(id_mod), 0, modnamelen, modname, modpathlen, modpath, nummaps)
for _ in range(nummaps):
mapfilelen = struct.unpack_from('<L', data, offset=pos)
mapfilelen = mapfilelen[0]
mapfile = data[mapnamelen + 12:mapnamelen + 12 + mapfilelen]
modfile_bytes += struct.pack('<L{}s'.format(mapfilelen), mapfilelen, mapfile)
pos = pos + 4 + mapfilelen
modfile_bytes += b'\x33\xFF\x22\xFF\x02\x00\x00\x00\x01'
with open("{}/modmeta.info".format(modextractdir), 'ab') as f:
if os.path.isfile("{}/modmeta.info".format(modextractdir)):
f.write(open("{}/modmeta.info".format(modextractdir), 'rb').read())
else:
f.write(b'\x01\x00\x00\x00\x08\x00\x00\x00ModType\x00\x02\x00\x00\x001\x00')
with open("{}/modmeta.info".format(modextractdir), 'ab') as f:
if os.path.isfile("{}/modmeta.info".format(modextractdir)):
f.write(open("{}/modmeta.info".format(modextractdir), 'rb').read())
else:
f.write(b'\x01\x00\x00\x00\x08\x00\x00\x00ModType\x00\x02\x00\x00\x001\x00')
with open(modextractdir + '.mod', 'wb') as f:
f.write(modfile_bytes)
with open(modextractdir + '.mod', 'wb') as f:
f.write(modfile_bytes)
if modextractdir != mod_ark_mods:
if not os.path.isdir(mod_ark_mods):