This commit is contained in:
Евгений Храмов 2023-05-14 12:30:46 +03:00
parent 4956e04d18
commit 6902648796

96
hlna.py

@ -1,6 +1,10 @@
#!/usr/bin/env python3
import os
import re
import struct
import shutil
import datetime
import subprocess
import yaml
import click
@ -356,18 +360,93 @@ WantedBy=default.target
@click.option('-m', default='all', help="Название карты для запуска или all для запуска все карт")
def modinstall(g, m):
if g == "ark":
id_game = "346110"
id_game_workshop = "346110"
if not os.path.isdir(dir_workshop_ark):
create_dir(dir_workshop_ark)
id_mods_ark = input("""Укажите id модов через запятую
:""")
os.environ.get('mod_branch', 'Windows')
os.system(f"steamcmd +login anonymous +workshop_download_item {id_game} {id_mods_ark} +quit")
os.system(f"mv {home_dir}/.local/share/Steam/steamapps/workshop/content/{id_game}/{id_mods_ark}/ {dir_server_ark}ShooterGame/Content/Mods/")
os.system(f"steamcmd +login anonymous +workshop_download_item {id_game_workshop} {id_mods_ark} +quit")
modextract(id_mods_ark, id_game_workshop)
@hlna.command()
@click.option("-m", required=True, help="Название Сервера")
@click.option("-e/-d", default=True, help="-e активировать карты, -d деактивировать")
def modextract(id_mods_ark, id_game_workshop):
mod_steam_workshop = "{}/content/{}/{}".format(dir_workshop_ark, id_game_workshop, id_mods_ark)
mod_ark_mods = "{}{}".format(dir_mods_ark, id_mods_ark)
modextractdir = mod_ark_mods
if id_mods_ark == "111111111":
return
if os.path.isfile("{}/WindowsNoEditor/mod.info".format(mod_steam_workshop)):
mod_steam_workshop = "{}/WindowsNoEditor".format(mod_steam_workshop)
for dirpath, dirnames, filenames in os.walk(mod_steam_workshop):
for dname in dirnames:
os.makedirs(os.path.join(modextractdir, os.path.relpath(os.path.join(dirpath, dname), mod_steam_workshop)), exist_ok=True)
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)
modname = subprocess.check_output(['curl', '-s', 'http://steamcommunity.com/sharedfiles/filedetails/?id={}'.format(id_mods_ark)]).decode('utf-8')
modname = re.search(r'<div class="workshopItemTitle">(.+)</div>', modname)
mod_name = modname and modname.group(1)
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 = (mod_name + mapname + "\x00").encode('utf-8')
modnamelen = len(modname)
modpath = ("../../../" + "ShooterGame" + "/Content/Mods/" + id_mods_ark + "\x00").encode('utf-8')
modpathlen = len(modpath)
modfile_bytes += struct.pack('<LLL{}sL{}sL'.format(modnamelen, modpathlen),
id_mods_ark, 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(modextractdir + '.mod', 'wb') as f:
f.write(modfile_bytes)
if modextractdir != mod_ark_mods:
if not os.path.isdir(mod_ark_mods):
os.makedirs(mod_ark_mods)
@ hlna.command()
@ click.option("-m", required=True, help="Название Сервера")
@ click.option("-e/-d", default=True, help="-e активировать карты, -d деактивировать")
def enablemap(m, e):
"""Включение/выключение карт"""
m = m.split(",")
@ -609,8 +688,9 @@ dir_unit = f"{home_dir}/.config/systemd/user/"
dir_logs = f"{dir_config}logs/"
dir_server_ark = f"{dir_server}ARK/"
dir_workshop_ark = f"{dir_server_ark}steamapps/workshop/"
dir_server_exec = f"{dir_server_ark}ShooterGame/Binaries/Linux/"
dir_workshop_ark = f"{home_dir}/.local/share/Steam/steamapps/workshop/"
dir_mods_ark = f"{dir_server_ark}ShooterGame/Content/Mods/"
dir_server_7days = f"{dir_server}/7Days/"
@ -626,3 +706,5 @@ create_dir(dir_logs)
if __name__ == '__main__':
hlna()