[cli/core] Add option to launch games via Origin (Windows only)

This commit is contained in:
derrod 2021-09-03 22:59:47 +02:00
parent 6876371325
commit ba6ec3ecca
2 changed files with 48 additions and 2 deletions

View file

@ -12,7 +12,6 @@ import time
import webbrowser import webbrowser
from distutils.util import strtobool from distutils.util import strtobool
from getpass import getuser
from logging.handlers import QueueListener from logging.handlers import QueueListener
from multiprocessing import freeze_support, Queue as MPQueue from multiprocessing import freeze_support, Queue as MPQueue
from sys import exit, stdout from sys import exit, stdout
@ -194,7 +193,13 @@ class LegendaryCLI:
for game in games: for game in games:
print(f' * {game.app_title} (App name: {game.app_name} | Version: {game.app_version})') print(f' * {game.app_title} (App name: {game.app_name} | Version: {game.app_version})')
if not game.app_version: if not game.app_version:
print(' ! This game has to be activated and installed through third-party store (not supported)') _custom_attribs = game.metadata.get('customAttributes', {})
_store = _custom_attribs.get('ThirdPartyManagedApp', {}).get('value', 'Unknown')
if os.name == 'nt' and _store == 'Origin':
print(f' - This game has to be activated, installed, and launched via Origin, use '
f'"legendary launch --origin {game.app_name}" to activate and/or run the game.')
else:
print(f' ! This game has to be installed through third-party store ({_store}, not supported)')
for dlc in dlc_list[game.asset_info.catalog_item_id]: for dlc in dlc_list[game.asset_info.catalog_item_id]:
print(f' + {dlc.app_title} (App name: {dlc.app_name} | Version: {dlc.app_version})') print(f' + {dlc.app_title} (App name: {dlc.app_name} | Version: {dlc.app_version})')
if not dlc.app_version: if not dlc.app_version:
@ -456,6 +461,9 @@ class LegendaryCLI:
def launch_game(self, args, extra): def launch_game(self, args, extra):
app_name = args.app_name app_name = args.app_name
if args.origin:
return self.launch_origin(args)
igame = self.core.get_installed_game(app_name) igame = self.core.get_installed_game(app_name)
if not igame: if not igame:
logger.error(f'Game {app_name} is not currently installed!') logger.error(f'Game {app_name} is not currently installed!')
@ -536,6 +544,18 @@ class LegendaryCLI:
logger.debug('Environment overrides:', env) logger.debug('Environment overrides:', env)
subprocess.Popen(params, cwd=cwd, env=env) subprocess.Popen(params, cwd=cwd, env=env)
def launch_origin(self, args):
# login is not required to launch the game, but linking does require it.
if not args.offline:
logger.info('Logging in...')
if not self.core.login():
logger.error('Login failed, cannot continue!')
exit(1)
origin_uri = self.core.get_origin_uri(args.app_name, args.offline)
logger.debug(f'Opening Origin URI: {origin_uri}')
webbrowser.open(origin_uri)
def install_game(self, args): def install_game(self, args):
if self.core.is_installed(args.app_name): if self.core.is_installed(args.app_name):
igame = self.core.get_installed_game(args.app_name) igame = self.core.get_installed_game(args.app_name)
@ -1277,12 +1297,16 @@ def main():
launch_parser.add_argument('--no-wine', dest='no_wine', action='store_true', launch_parser.add_argument('--no-wine', dest='no_wine', action='store_true',
default=strtobool(os.environ.get('LGDRY_NO_WINE', 'False')), default=strtobool(os.environ.get('LGDRY_NO_WINE', 'False')),
help='Do not run game with WINE (e.g. if a wrapper is used)') help='Do not run game with WINE (e.g. if a wrapper is used)')
launch_parser.add_argument('--origin', dest='origin', help=argparse.SUPPRESS,
action='store_true', default=False)
else: else:
# hidden arguments to not break this on Windows # hidden arguments to not break this on Windows
launch_parser.add_argument('--wine', help=argparse.SUPPRESS, dest='wine_bin') launch_parser.add_argument('--wine', help=argparse.SUPPRESS, dest='wine_bin')
launch_parser.add_argument('--wine-prefix', help=argparse.SUPPRESS, dest='wine_pfx') launch_parser.add_argument('--wine-prefix', help=argparse.SUPPRESS, dest='wine_pfx')
launch_parser.add_argument('--no-wine', dest='no_wine', help=argparse.SUPPRESS, launch_parser.add_argument('--no-wine', dest='no_wine', help=argparse.SUPPRESS,
action='store_true', default=True) action='store_true', default=True)
launch_parser.add_argument('--origin', dest='origin', action='store_true',
help='Launch Origin to activate or run the game.')
list_parser.add_argument('--platform', dest='platform_override', action='store', metavar='<Platform>', list_parser.add_argument('--platform', dest='platform_override', action='store', metavar='<Platform>',
type=str, help='Override platform that games are shown for (e.g. Win32/Mac)') type=str, help='Override platform that games are shown for (e.g. Win32/Mac)')

View file

@ -15,6 +15,7 @@ from requests import session
from requests.exceptions import HTTPError from requests.exceptions import HTTPError
from typing import List, Dict from typing import List, Dict
from uuid import uuid4 from uuid import uuid4
from urllib.parse import urlencode
from legendary import __version__ from legendary import __version__
from legendary.api.egs import EPCAPI from legendary.api.egs import EPCAPI
@ -483,6 +484,27 @@ class LegendaryCore:
return params, working_dir, env return params, working_dir, env
def get_origin_uri(self, app_name: str, offline: bool = False) -> str:
if offline:
token = '0'
else:
token = self.egs.get_game_token()['code']
user_name = self.lgd.userdata['displayName']
account_id = self.lgd.userdata['account_id']
parameters = [
('AUTH_PASSWORD', token),
('AUTH_TYPE', 'exchangecode'),
('epicusername', user_name),
('epicuserid', account_id),
('epiclocale', self.language_code),
('theme', 'sws'),
('platform', 'epic'),
('Hotfix', 'go')
]
return f'link2ea://launchgame/{app_name}?{urlencode(parameters)}'
def get_save_games(self, app_name: str = ''): def get_save_games(self, app_name: str = ''):
savegames = self.egs.get_user_cloud_saves(app_name, manifests=not not app_name) savegames = self.egs.get_user_cloud_saves(app_name, manifests=not not app_name)
_saves = [] _saves = []