Created
January 23, 2024 05:06
-
-
Save Dregu/36a53b43ff34c6a70370f62943b0a2b6 to your computer and use it in GitHub Desktop.
Import all currently subscribed Poly Bridge 3 Weekly Challenge workshop layouts to default profile sandbox
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Import all currently subscribed Poly Bridge 3 Weekly Challenge workshop layouts to default profile sandbox | |
import urllib.request | |
import re | |
import sys | |
import winreg | |
import os | |
import math | |
import string | |
import shutil | |
def get_steam_dirs(): | |
try: | |
hkey = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\WOW6432Node\\Valve\\Steam") | |
except: | |
hkey = None | |
print(sys.exc_info()) | |
try: | |
steam_path = winreg.QueryValueEx(hkey, "InstallPath") | |
except: | |
steam_path = None | |
print(sys.exc_info()) | |
folders = [] | |
if not steam_path: | |
folders.append("C:\\Program Files (x86)\\Steam") | |
else: | |
folders.append(steam_path[0]) | |
if not os.path.isdir(folders[0]): | |
return [] | |
with open(folders[0] + "\\steamapps\\libraryfolders.vdf") as f: | |
lf = f.read() | |
folders.extend([fn.replace("\\\\", "\\") for fn in | |
re.findall(r'^\s*"path"\t+"([^"]*)"', lf, re.MULTILINE)]) | |
folders = list(dict.fromkeys(folders)) | |
return folders | |
def get_name_from_workshop(wsid): | |
name = "" | |
with urllib.request.urlopen("https://steamcommunity.com/sharedfiles/filedetails/?id=" + wsid) as res: | |
html = res.read().decode("utf8") | |
for m in re.findall(r'<title>Steam Workshop::([^<]+)<', html, re.MULTILINE): | |
name = m | |
return name | |
def get_name_from_layout(layout): | |
with open(layout, "rb") as f: | |
data = f.read() | |
hex = data.hex().upper() | |
for m in re.finditer(r'01010101010101([A-F0-9]{2})', hex): | |
n = int(m.group()[14:], 16) | |
i = int(m.end()/2)+1 | |
name = data[i:i+n].decode("utf8") | |
return name | |
return "" | |
def import_layout(wc, wsid, num): | |
for dir in dirs: | |
layout = dir + "\\steamapps\\workshop\\content\\1850160\\" + wsid + "\\steam_workshop_level.layout" | |
if not os.path.isfile(layout): | |
continue | |
season = "S{:02d}".format(math.floor((num-1) / 10) + 1) | |
week = "W{:02d}".format(((num-1) % 10) + 1) | |
#name = get_name_from_workshop(wsid) | |
name = get_name_from_layout(layout) | |
filename = season + week + " " + name | |
filename = ''.join(c for c in filename if c not in "\\/:*?\"<>|") | |
subdir = wc + "\\" + season | |
os.makedirs(subdir, exist_ok=True) | |
dest = subdir + "\\" + filename + ".layout" | |
shutil.copy2(layout, dest) | |
print(layout, "\n ->", dest) | |
def import_weeklies(): | |
wc = profile + "\\Sandbox\\WC" | |
print("Importing all subscribed weeklies to '" + wc + "'") | |
url = "https://pb3game.s3.us-east-2.amazonaws.com/weeklies/manifest" | |
with urllib.request.urlopen(url) as res: | |
html = res.read().decode("utf8") | |
for line in html.splitlines()[1:]: | |
parts = re.split(r'\t+', line) | |
if len(parts) == 3: | |
import_layout(wc, parts[0], int(parts[2])) | |
profile = "{USERPROFILE}\\AppData\\LocalLow\\Dry Cactus\\Poly Bridge 3\\Profiles\\Default".format(**os.environ) | |
dirs = get_steam_dirs() | |
if len(dirs) == 0: | |
print("Error: Can't find Steam install directories") | |
elif not os.path.isdir(profile): | |
print("Error: Can't find default profile in '" + profile + "'") | |
else: | |
import_weeklies() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment