alex47exe ae979f1edb * [alex47exe] major overhaul of **generate_emu_config** - custom configs, proper ini parsing, better logging and error handling, helper tools:
* add `-def1` ... `-def5` arguments, which can be used to generate your preferred custom config
    if no `-def` argument is provided, `-def1` will be used by default, to automatically copy from the following folders:
    * `.\_DEFAULT\0` ............... essential emu files, like latest GSE dlls (*steam_api.dll* and *steam_api64.dll*)
    * `.\_DEFAULT\1` ............... other GSE files and folders, including default ini files
    * `.\_DEFAULT\<appid>` ... other GSE files and folders, but only for the current `<appid>`, if the folder exists
  * (Windows only) add some useful helper tools, written in *AutoIt3*:
    * **gse_acw_helper.exe** - add the required achievements schema db files for *Achievement Watcher*, if  .\steam_misc\extra_acw\extra_acw.zip file exists (if generated by `generate_emu_config.exe -acw <appid>`)
    * **gse_debug_switch.exe** - automatically switch between release and debug versions of the emulator, if *steam_api.7z* / *steam_api64.7z* file exists (or *steamclient.7z* / *steamclient64.7z*, if you use the steamclient version)
      paths to release and debug files inside 7z, can be customized in .\steam_misc\tools\au3\scripts\gse_debug_switch.ini
    * **gse_generate_interfaces.exe** - simple x64-x86 launcher for *generate_interfaces.exe*
      it also writes all found steam interfaces to CODEX *steam_emu.ini* (if generated by `generate_emu_config -cdx <appid>`)
      make sure to name your original dll to one of these formats, so it can automatically find its interfaces:
      * `valve_api.dll / valve_api64.dll`
      * `steam_api.dll.bak / steam_api64.dll.bak` or `steam_api.dll.org / steam_api64.dll.org`
      * `steam_api.bak / steam_api64.bak` or `steam_api.org / steam_api64.org`
      * `steam_api_orig.dll / steam_api64_orig.dll` or `steam_api_legit.dll / steam_api64_legit.dll`
    * **gse_lobby_connect.exe** - simple x64-x86 launcher for *lobby_connect.exe*
  * new folder structure, compatible with current and future helper tools --- default arguments are `-acw -cdx -clr <appid>`
    NEVER delete `.\steam_misc\app_backup`, `.\steam_misc\app_info`, `.\steam_misc\tools` and `.\steam_settings` folders
    MIGHT need `.\steam_misc\extra_acw` and `.\steam_misc\extra_cdx` for compatibility with Achievement Watcher and CODEX
  * add `-scx` argument to automatically download images / videos for trading cards, backgrounds, badges, emoticons and other tradable items
    unfortunately I couldn't find any direct steam api method to download the files, so I had to write a rudimentary web scrapper to extract the download links from a third-party website, hence the *scx_gen.py* script might need updating in the future if the website design changes
  * download screenshots and videos:
    * download thumbnails for both screenshots and videos, and compress them to `.zip` files
    * screenshots and videos are now numbered from first to last published, as in the Steam store page
    * add `-vids_low` / `-vids_max` arguments to download all videos, in low and / or high quality
  * create / update .\\*top_owners_ids.txt* when .\\*top_owners_ids.html* is present
  * generate controller action sets txt files for all found controller vdf configs, and zip them inside .\steam_misc\app_backup\app_backup.zip
    by default, the emu supports only `xboxone` and `xbox360` controller configs, though if the're are any issues with the default supported controller action sets inside .\steam_settings\controller folder, you could try to unpack and overwrite action sets for other unsupported controller configs
  * (Windows only) add *AdvancedRun* launchers (cmd console + silent) for `.bat` files and `.py` scripts
* **[alex47exe]** major overhaul of **migrate_gse** - uses the same `.\_DEFAULT\0` and `.\_DEFAULT\1` folder structure for default configs
  it can convert old `.txt` format to `.ini` format, minus *branches.json*, which would require using *top_owners_ids.txt* and some login code from **generate_emu_config**, which should actually be used to properly generate the config files, instead of converting from the old `.txt` format
* [alex47exe] *generate_interfaces.exe* - find all Steam Interfaces instead of only old ones
  the emu will ignore the ones it doesn't require, while we'll have the complete list to write it to CODEX *steam_emu.ini*
* [alex47exe] *lobby_connect.exe* - improve cmd console text alignment
* [alex47exe] `mods_img` instead of `mod_images` (better folder consistency), better example for `mods_img`, minor tweaks to `.ini` and `.md` files
2024-07-30 01:21:09 +01:00

184 lines
7.4 KiB
Python

import copy
import os
import time
import json
import shutil
def __ClosestDictKey(targetKey : str, srcDict : dict[str, object] | set[str]) -> str | None:
for k in srcDict:
if k.lower() == f"{targetKey}".lower():
return k
return None
def __generate_ach_watcher_schema(lang: str, app_id: int, achs: list[dict]) -> list[dict]:
print(f"[ ] __ writing {lang} {app_id}.db to '.\\schema\\{lang}' folder")
out_achs_list = []
for idx in range(len(achs)):
ach = copy.deepcopy(achs[idx])
out_ach_data = {}
# adjust the displayName
displayName = ""
ach_displayName = ach.get("displayName", None)
if ach_displayName:
if type(ach_displayName) == dict: # this is a dictionary
displayName : str = ach_displayName.get(lang, "")
if not displayName and ach_displayName: # has some keys but language not found
print(f"[X] ____ Missing {lang} language in 'displayName' of achievement {ach['name']}")
nearestLang = __ClosestDictKey(lang, ach_displayName)
if nearestLang:
print(f"[ ] ____ Using 'displayName' from {nearestLang} language")
displayName = ach_displayName[nearestLang]
else:
print(f"[ ] ____ Using 'displayName' from the first language")
displayName : str = list(ach_displayName.values())[0]
else: # single string (or anything else)
displayName = ach_displayName
del ach["displayName"]
else:
print(f"[X] ____ Missing 'displayName' in achievement {ach['name']}")
out_ach_data["displayName"] = displayName
desc = ""
ach_desc = ach.get("description", None)
if ach_desc:
if type(ach_desc) == dict: # this is a dictionary
desc : str = ach_desc.get(lang, "")
if not desc and ach_desc: # has some keys but language not found
print(f"[X] ____ Missing {lang} language in 'description' of achievement {ach['name']}")
nearestLang = __ClosestDictKey(lang, ach_desc)
if nearestLang:
print(f"[ ] ____ Using 'description' from {nearestLang} language")
desc = ach_desc[nearestLang]
else:
print(f"[ ] ____ Using 'description' from the first language")
desc : str = list(ach_desc.values())[0]
else: # single string (or anything else)
desc = ach_desc
del ach["description"]
else:
print(f"[X] ____ Missing 'description' in achievement {ach['name']}")
# adjust the description
out_ach_data["description"] = desc
# copy the rest of the data
out_ach_data.update(ach)
# add links to icon, icongray, and icon_gray
base_icon_url = r'https://cdn.cloudflare.steamstatic.com/steamcommunity/public/images/apps'
icon_hash = out_ach_data.get("icon", None)
if icon_hash:
out_ach_data["icon"] = f'{base_icon_url}/{app_id}/{icon_hash}'
else:
out_ach_data["icon"] = ""
icongray_hash = out_ach_data.get("icongray", None)
if icongray_hash:
out_ach_data["icongray"] = f'{base_icon_url}/{app_id}/{icongray_hash}'
else:
out_ach_data["icongray"] = ""
icon_gray_hash = out_ach_data.get("icon_gray", None)
if icon_gray_hash:
del out_ach_data["icon_gray"] # use the old key
out_ach_data["icongray"] = f'{base_icon_url}/{app_id}/{icon_gray_hash}'
if "hidden" in out_ach_data:
try:
out_ach_data["hidden"] = int(out_ach_data["hidden"])
except Exception as e:
pass
else:
out_ach_data["hidden"] = 0
out_achs_list.append(out_ach_data)
return out_achs_list
def generate_all_ach_watcher_schemas(
base_out_dir : str,
appid: int,
app_name : str,
app_exe : str,
achs: list[dict],
small_icon_hash : str) -> None:
ach_watcher_out_dir = os.path.join(base_out_dir, "steam_misc", "extra_acw", "steam_cache", "schema")
if not achs:
#print("[X] Couldn't generate Achievement Watcher schemas, no achievements found") # move notification to main script
return
else:
print(f"[ ] Generating Achievement Watcher schemas...")
#if app_exe:
# print(f"[ ] __ Detected app exe: '{app_exe}'") # move notification to main script
#else:
# print(f"[X] __ Cannot detect app exe") # move notification to main script
small_icon_url = ''
if small_icon_hash:
small_icon_url = f"https://cdn.cloudflare.steamstatic.com/steamcommunity/public/images/apps/{appid}/{small_icon_hash}.jpg"
images_base_url = r'https://cdn.cloudflare.steamstatic.com/steam/apps'
ach_watcher_base_schema = {
"appid": appid,
"name": app_name,
"binary": app_exe,
"achievement": {
"total": len(achs),
},
"img": {
"header": f"{images_base_url}/{appid}/header.jpg",
"background": f"{images_base_url}/{appid}/page_bg_generated_v6b.jpg",
"portrait": f"{images_base_url}/{appid}/library_600x900.jpg",
"hero": f"{images_base_url}/{appid}/library_hero.jpg",
"icon": small_icon_url,
},
"apiVersion": 1,
}
langs : set[str] = set()
for ach in achs:
displayNameLangs = ach.get("displayName", None)
if displayNameLangs and type(displayNameLangs) == dict:
langs.update(list(displayNameLangs.keys()))
descriptionLangs = ach.get("description", None)
if descriptionLangs and type(descriptionLangs) == dict:
langs.update(list(descriptionLangs.keys()))
if "token" in langs:
langs.remove("token")
tokenKey = __ClosestDictKey("token", langs)
if tokenKey:
langs.remove(tokenKey)
if not langs:
print(f"[X] __ Cannot detect supported languages")
print(f"[ ] __ Assuming english is the only supported language")
langs = ["english"]
print(f"[ ] __ schema = OUTPUT\\{appid}\\steam_misc\\achievement_watcher\\steam_cache\\schema")
for lang in langs:
out_schema_folder = os.path.join(ach_watcher_out_dir, lang)
if not os.path.exists(out_schema_folder):
os.makedirs(out_schema_folder)
time.sleep(0.050)
out_schema = copy.copy(ach_watcher_base_schema)
out_schema["achievement"]["list"] = __generate_ach_watcher_schema(lang, appid, achs)
out_schema_file = os.path.join(out_schema_folder, f'{appid}.db')
with open(out_schema_file, "wt", encoding='utf-8') as f:
json.dump(out_schema, f, ensure_ascii=False, indent=2)
shutil.make_archive(os.path.join(base_out_dir, "steam_misc\\extra_acw"), 'zip', os.path.join(base_out_dir, "steam_misc\\extra_acw")) # first argument is the name of the zip file
shutil.rmtree(os.path.join(base_out_dir, "steam_misc\\extra_acw"))
os.makedirs(os.path.join(base_out_dir, "steam_misc\\extra_acw"))
shutil.move(os.path.join(base_out_dir, 'steam_misc\\extra_acw.zip'), os.path.join(base_out_dir, "steam_misc\\extra_acw\\extra_acw.zip"))