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