Last active
April 5, 2022 20:57
-
-
Save Eklei/dd7acc63fd87aebb940bd6c72e1d27ea to your computer and use it in GitHub Desktop.
This Python 3.0 script (courtesy of Dunto) finds any Starbound mods installed from the Steam workshop and adds them to the search path in sbinit.config.
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
#!/usr/bin/python | |
# From: http://community.playstarbound.com/threads/steam-workshop-mod-loader.119587/ | |
# And: https://gist.github.com/Dunto/4f1396a784802bfbda12a029796c0f4b | |
# That was before Dunto sent this own valuable content into the memory hole. | |
# So here it is, back from the grave, because as I'm sure you know, the | |
# Internet interprets censorship as damage and routes around it. | |
# I have edited it to exclude workshop mod directories that are empty. | |
# ~~~ | |
# This script will allow Starbound to load Steam workshop mods without moving | |
# files around. It works by updating the sbinit.config file to include the | |
# Steam workshop mod folders. Since Starbound will not look deeper than one | |
# folder level for for mods, each mod's workshop folder must be specified. | |
# Running this script synchronizes the sbinit.config mod search paths with | |
# the folders in the Steam workshop downloads folder for Starbound. | |
# This script only needs to be run if you add or remove workshop mods, | |
# it does not need to be run if your current mods simply update. | |
# Copyright 2016 Dunto, see below for license information. | |
# This script was written as a quick solution to a personal requirement, | |
# it may or may not be improved on as time passes. I make no promises | |
# as to whether it will work properly for you or not. | |
# This program is free software: you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation, either version 3 of the License, or | |
# (at your option) any later version. | |
# | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# | |
# You should have received a copy of the GNU General Public License | |
# along with this program. If not, see <http://www.gnu.org/licenses/> | |
import os | |
import json | |
def getSbInstallPath(): | |
if os.name == 'posix': | |
return os.path.expanduser("~/.steam/steam/steamapps/common/Starbound/") | |
elif os.name == 'nt': | |
return os.path.expandvars("%ProgramFiles(x86)%\\Steam\\steamapps\\common\\Starbound\\") | |
else: | |
raise Exception("Error: Unable to determine operating system!") | |
def getOsDirs(): | |
if os.name == 'posix': | |
return ["linux", "osx"] | |
elif os.name == 'nt': | |
return ["win32", "win64"] | |
else: | |
raise Exception("Error: Unable to determine operating system!") | |
def loadInitConfig(init_path): | |
INIT_FP = open(os.path.join(init_path, "sbinit.config"), 'r') | |
init_data = json.load(INIT_FP) | |
INIT_FP.close() | |
return init_data | |
def storeInitConfig(init_data, init_path): | |
INIT_FP = open(os.path.join(init_path, "sbinit.config"), 'w') | |
json.dump(init_data, INIT_FP, indent=2) | |
INIT_FP.close() | |
# begin main | |
STARBOUND_INSTALL_PATH = getSbInstallPath() | |
STEAM_STARBOUND_WORKSHOP_PATH = os.path.normpath(os.path.join(STARBOUND_INSTALL_PATH,"..","..","workshop","content","211820")) | |
STEAM_STARBOUND_WORKSHOP_RELPATH = os.path.join("..","..","..","workshop","content","211820") | |
STARBOUND_BASE_ASSET_DIRS = ["../assets", "../mods"] | |
# If you have a custom Steam library location, you'll need to manually set | |
# these variables to the correct folder paths and uncomment them. | |
#STARBOUND_INSTALL_PATH="/path/to/starbound/folder" | |
#STEAM_STARBOUND_WORKSHOP_PATH="/path/to/steam/workshop/content/211820/folder" | |
#for os_dir in getOsDirs(): | |
for os_dir in ["linux", "osx", "win32", "win64"]: | |
# Load sbinit.config | |
init_data = loadInitConfig(os.path.join(STARBOUND_INSTALL_PATH, os_dir)) | |
# Remove all mod folder entries and re-add base entries | |
init_data["assetDirectories"] = [] | |
for base_dir in STARBOUND_BASE_ASSET_DIRS: | |
init_data["assetDirectories"].append(os.path.normpath(base_dir)) | |
# Add workshop mod entries | |
if os.path.isdir(STEAM_STARBOUND_WORKSHOP_PATH): | |
for entry in os.listdir(STEAM_STARBOUND_WORKSHOP_PATH): | |
if os.path.isdir(os.path.join(STEAM_STARBOUND_WORKSHOP_PATH, entry)): | |
if os.listdir(os.path.join(STEAM_STARBOUND_WORKSHOP_PATH, entry)): | |
init_data["assetDirectories"].append(os.path.join(STEAM_STARBOUND_WORKSHOP_RELPATH, entry)) | |
# Store updated sbinit.config | |
storeInitConfig(init_data, os.path.join(STARBOUND_INSTALL_PATH, os_dir)) | |
print("\nUpdated Starbound with Steam workshop mods!\n") | |
os.system("pause") | |
# end main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment