Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions addons/mod_loader/api/third_party/steam.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
class_name ModLoaderSteam
extends Node

const LOG_NAME := "ModLoader:ThirdParty:Steam"

# Methods related to Steam and the Steam Workshop


# Get the path to the Steam workshop folder. Only works for Steam games, as it
# traverses directories relative to where a Steam game and its workshop content
# would be installed. Based on code by Blobfish (developer of Brotato).
# For reference, these are the paths of a Steam game and its workshop folder:
# GAME = Steam/steamapps/common/GameName
# WORKSHOP = Steam/steamapps/workshop/content/AppID
# Eg. Brotato:
# GAME = Steam/steamapps/common/Brotato
# WORKSHOP = Steam/steamapps/workshop/content/1942280
static func get_steam_workshop_dir() -> String:
var game_install_directory := ModLoaderUtils.get_local_folder_dir()
var path := ""

# Traverse up to the steamapps directory (ie. `cd ..\..\` on Windows)
var path_array := game_install_directory.split("/")
path_array.resize(path_array.size() - 2)

# Reconstruct the path, now that it has "common/GameName" removed
path = "/".join(path_array)

# Append the workgame's workshop path
path = path.plus_file("workshop/content/" + get_steam_app_id())

return path


# Gets the steam app ID from steam_data.json, which should be in the root
# directory (ie. res://steam_data.json). This file is used by Godot Workshop
# Utility (GWU), which was developed by Brotato developer Blobfish:
# https://github.com/thomasgvd/godot-workshop-utility
static func get_steam_app_id() -> String:
var game_install_directory := ModLoaderUtils.get_local_folder_dir()
var steam_app_id := ""
var file := File.new()

if file.open(game_install_directory.plus_file("steam_data.json"), File.READ) == OK:
var file_content: Dictionary = parse_json(file.get_as_text())
file.close()

if not file_content.has("app_id"):
ModLoaderUtils.log_error("The steam_data file does not contain an app ID. Mod uploading will not work.", LOG_NAME)
return ""

steam_app_id = file_content.app_id
else :
ModLoaderUtils.log_error("Can't open steam_data file, \"%s\". Please make sure the file exists and is valid." % game_install_directory.plus_file("steam_data.json"), LOG_NAME)

return steam_app_id
2 changes: 1 addition & 1 deletion addons/mod_loader/mod_loader.gd
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ func _load_zips_in_folder(folder_path: String) -> int:
# inside each workshop item's folder
func _load_steam_workshop_zips() -> int:
var temp_zipped_mods_count := 0
var workshop_folder_path := ModLoaderUtils.get_steam_workshop_dir()
var workshop_folder_path := ModLoaderSteam.get_steam_workshop_dir()

if not ml_options.steam_workshop_path_override == "":
workshop_folder_path = ml_options.steam_workshop_path_override
Expand Down
5 changes: 5 additions & 0 deletions addons/mod_loader/mod_loader_setup.gd
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ const new_global_classes := [
"class": "ModLoaderOptionsProfile",
"language": "GDScript",
"path": "res://addons/mod_loader/options/classes/options_profile.gd"
}, {
"base": "Node",
"class": "ModLoaderSteam",
"language": "GDScript",
"path": "res://addons/mod_loader/api/third_party/steam.gd"
}, {
"base": "Node",
"class": "ModLoaderDeprecated",
Expand Down
53 changes: 0 additions & 53 deletions addons/mod_loader/mod_loader_utils.gd
Original file line number Diff line number Diff line change
Expand Up @@ -532,56 +532,3 @@ static func save_string_to_file(save_string: String, filepath: String) -> bool:
static func save_dictionary_to_json_file(data: Dictionary, filepath: String) -> bool:
var json_string = JSON.print(data, "\t")
return save_string_to_file(json_string, filepath)


# Steam
# =============================================================================

# Get the path to the Steam workshop folder. Only works for Steam games, as it
# traverses directories relative to where a Steam game and its workshop content
# would be installed. Based on code by Blobfish (developer of Brotato).
# For reference, these are the paths of a Steam game and its workshop folder:
# GAME = Steam/steamapps/common/GameName
# WORKSHOP = Steam/steamapps/workshop/content/AppID
# Eg. Brotato:
# GAME = Steam/steamapps/common/Brotato
# WORKSHOP = Steam/steamapps/workshop/content/1942280
static func get_steam_workshop_dir() -> String:
var game_install_directory := get_local_folder_dir()
var path := ""

# Traverse up to the steamapps directory (ie. `cd ..\..\` on Windows)
var path_array := game_install_directory.split("/")
path_array.resize(path_array.size() - 2)

# Reconstruct the path, now that it has "common/GameName" removed
path = "/".join(path_array)

# Append the workgame's workshop path
path = path.plus_file("workshop/content/" + get_steam_app_id())

return path


# Gets the steam app ID from steam_data.json, which should be in the root
# directory (ie. res://steam_data.json). This file is used by Godot Workshop
# Utility (GWU), which was developed by Brotato developer Blobfish:
# https://github.com/thomasgvd/godot-workshop-utility
static func get_steam_app_id() -> String:
var game_install_directory := get_local_folder_dir()
var steam_app_id := ""
var file := File.new()

if file.open(game_install_directory.plus_file("steam_data.json"), File.READ) == OK:
var file_content: Dictionary = parse_json(file.get_as_text())
file.close()

if not file_content.has("app_id"):
log_error("The steam_data file does not contain an app ID. Mod uploading will not work.", LOG_NAME)
return ""

steam_app_id = file_content.app_id
else :
log_error("Can't open steam_data file, \"%s\". Please make sure the file exists and is valid." % game_install_directory.plus_file("steam_data.json"), LOG_NAME)

return steam_app_id