Skip to content

Commit

Permalink
improve steamdrm
Browse files Browse the repository at this point in the history
  • Loading branch information
mastercoms committed Aug 6, 2024
1 parent 3b7a164 commit 80fa726
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
37 changes: 24 additions & 13 deletions pbpy/pbsteamcmd.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pathlib import Path
import shutil
from pathlib import Path

from pbpy import pblog, pbtools, pbconfig
from pbpy import pbconfig, pblog, pbtools


def publish_build(
Expand All @@ -11,6 +11,7 @@ def publish_build(
app_script,
drm_app_id,
drm_exe_path,
drm_useonprem,
):
# Test if our configuration values exist
if not app_script:
Expand All @@ -32,13 +33,14 @@ def steam_log(log):
pblog.info("[steamcmd] " + log)

# if drm wrapping is configured
nondrm_bytes = None
if drm_app_id and drm_exe_path:
drm_exe_path = Path(drm_exe_path)
if not Path.is_absolute(drm_exe_path):
if not drm_exe_path.is_absolute():
drm_exe_path = (
Path(pbconfig.config_filepath).parent / drm_exe_path
).resolve()
if not Path.is_file(drm_exe_path):
if not drm_exe_path.is_file():
pblog.error("steamcmd/drm/targetbinary does not exist.")
return False
drm_command = base_steamcmd_command.copy()
Expand All @@ -54,32 +56,41 @@ def steam_log(log):
str(drm_output),
"drmtoolp",
"6",
"local",
"local" if drm_useonprem else "cloud",
"+quit",
]
) # the drm wrap command https://partner.steamgames.com/doc/features/drm
pblog.info("Wrapping game with steamworks DRM...")
pblog.info("Wrapping game with Steamworks DRM...")
drm_proc = pbtools.run_stream(drm_command, logfunc=steam_log)
pbtools.remove_file(str(drm_exe_path)) # remove original file in any case
if drm_proc.returncode != 0:
pblog.error("Drm wrapping failed(%d)" % drm_proc.returncode)
if Path.exists(drm_output):
if drm_output.exists():
pbtools.remove_file(str(drm_output))
pbtools.error_state(
f"DRM wrapping failed: exit code {drm_proc.returncode}",
hush=True,
term=True,
)
return False

with open(drm_exe_path, "wb") as orig_file:
nondrm_bytes = orig_file.read()
pbtools.remove_file(str(drm_exe_path)) # remove original file on success
shutil.move(
str(drm_output), str(drm_exe_path)
) # move drm-wrapped file to location of original
else:
drm_exe_path = None

script_path = (Path() / app_script.format(branch_type)).resolve()
build_cmd = base_steamcmd_command.copy()
build_cmd.extend(["+run_app_build", script_path, "+quit"])
proc = pbtools.run_stream(build_cmd, logfunc=steam_log)
result = proc.returncode

if Path.is_file(drm_exe_path):
pbtools.remove_file(
drm_exe_path
) # remove drm wrapped file, so that a subsequent build will re-build a non-wrapped executable
if drm_exe_path and drm_exe_path.is_file():
# remove drm wrapped file and write the original file, so that a subsequent build will re-build a non-wrapped executable
pbtools.remove_file(drm_exe_path)
with open(drm_exe_path, "wb") as orig_file:
orig_file.write(nondrm_bytes)

return result
6 changes: 6 additions & 0 deletions pbsync/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,11 @@ def autoversion_handler(autoversion_val):
pbconfig.get("steamcmd_script"),
pbconfig.get("steamdrm_appid"),
pbconfig.get("steamdrm_targetbinary"),
(
True
if os.getenv("PBSYNC_STEAMDRM_USECLOUD")
else pbconfig.get("steamdrm_useonprem")
),
),
"butler": lambda publish_val, pubexe: pbbutler.publish_build(
publish_val,
Expand Down Expand Up @@ -880,6 +885,7 @@ def pbsync_config_parser_func(root):
"steamcmd_script": ("steamcmd/script", None, "", True),
"steamdrm_appid": ("steamcmd/drm/appid", None, "", True),
"steamdrm_targetbinary": ("steamcmd/drm/targetbinary", None, "", True),
"steamdrm_useonprem": ("steamcmd/drm/useonprem", None, True, True),
"resharper_version": ("resharper/version", None, "", True),
"engine_prefix": ("versionator/engineprefix", None, "", True),
"engine_type": ("versionator/enginetype", None, None, True),
Expand Down

0 comments on commit 80fa726

Please sign in to comment.