Compare commits

...
2 changed files with 79 additions and 3 deletions

No files matched your search

@@ -1594,6 +1594,15 @@ STEAM_EA_STATE = ".droiddeck-ea-steam.json"
STEAM_EA_CLIENT = "drive_c/Program Files/Electronic Arts/EA Desktop/EA Desktop/EADesktop.exe"
STEAM_EA_OFFER = re.compile(r"^(Origin\.OFR\.[0-9]+\.[0-9]+)\.dat$", re.IGNORECASE)
REPLACED = 13
STEAM_EA_LOCALES = {
"arabic": ("ar_SA",), "brazilian": ("pt_BR",), "bulgarian": ("bg_BG",), "czech": ("cs_CZ",), "danish": ("da_DK",),
"dutch": ("nl_NL",), "english": ("en_US",), "finnish": ("fi_FI",), "french": ("fr_FR",), "german": ("de_DE",),
"greek": ("el_GR",), "hungarian": ("hu_HU",), "indonesian": ("id_ID",), "italian": ("it_IT",), "japanese": ("ja_JP",),
"koreana": ("ko_KR",), "latam": ("es_MX",), "malay": ("ms_MY",), "norwegian": ("no_NO", "nb_NO"), "polish": ("pl_PL",),
"portuguese": ("pt_PT",), "romanian": ("ro_RO",), "russian": ("ru_RU",), "schinese": ("zh_CN",), "spanish": ("es_ES",),
"swedish": ("sv_SE",), "tchinese": ("zh_TW", "zh_HK"), "thai": ("th_TH",), "turkish": ("tr_TR",), "ukrainian": ("uk_UA",),
"vietnamese": ("vi_VN",),
}
def steam_ea_link(argv):
@@ -1623,6 +1632,7 @@ def ea_manifest(folder):
launcher = next((l for l in launchers if not l[2]), launchers[0] if launchers else None)
version = root.find("buildMetaData/gameVersion")
titles = {e.get("locale"): (e.text or "").strip() for e in root.iter("gameTitle") if e.get("locale")}
listed = [l.strip() for l in (root.findtext("installMetaData/locales") or "").split(",") if l.strip()]
exe = None
if launcher is not None:
relative = re.sub(r"^\[[^\]]*\]", "", launcher[0]).replace("{installLocation}", "").lstrip("\\/")
@@ -1633,6 +1643,7 @@ def ea_manifest(folder):
"parameters": launcher[1] if launcher else "",
"version": version.get("version", "") if version is not None else "",
"title": titles.get("en_US") or next(iter(titles.values()), "") or Path(folder).name,
"locales": listed or list(titles),
}
@@ -1645,6 +1656,27 @@ def steam_ea_offers(folder):
return [m.group(1) for m in map(STEAM_EA_OFFER.match, names) if m]
def steam_game_language(folder, appid):
try:
text = decode_output((Path(folder).parent.parent / ("appmanifest_%s.acf" % appid)).read_bytes())
except OSError:
text = ""
found = re.search(r'"UserConfig"\s*\{[^{}]*?"language"\s*"([^"]+)"', text, re.IGNORECASE)
return found.group(1) if found else os.environ.get("DD_STEAM_LANGUAGE", "")
def steam_ea_locale(available, language):
wanted = STEAM_EA_LOCALES.get(language.strip().lower(), ("en_US",))
for want in wanted:
exact = [l for l in available if l.casefold() == want.casefold()]
if exact:
return exact[0]
prefix = lambda l: l.casefold().split("_", 1)[0]
same = [l for l in available if prefix(l) == prefix(wanted[0])]
english = [l for l in available if prefix(l) == "en"]
return (same or english or ["en_US"])[0]
def batch_text(value):
return value.replace("%", "%%").replace('"', "")
@@ -1691,10 +1723,12 @@ def prepare_steam_ea(argv, compat_data, launch_dir):
log("steam ea: no channel to DroidDeck, left to the EA app")
return 0
exe = manifest["exe"]
appid = STEAM_EA_LINK.match(steam_ea_link(argv).strip().strip('"')).group(1)
locale = steam_ea_locale(manifest["locales"], steam_game_language(folder, appid))
sidecar = {"store": "ea", "id": offers[0], "title": manifest["title"],
"extra": {"contentIds": ",".join(manifest["contentIds"]), "displayName": manifest["title"], "locale": "en_US"}}
"extra": {"contentIds": ",".join(manifest["contentIds"]), "displayName": manifest["title"], "locale": locale}}
steam = {"folder": str(folder), "offers": offers, "contentIds": manifest["contentIds"], "title": manifest["title"],
"version": manifest["version"], "locale": "en_US", "exe": str(exe.relative_to(folder))}
"version": manifest["version"], "locale": locale, "exe": str(exe.relative_to(folder))}
answer = prepare_ea(folder, sidecar, compat_data, launch_dir, steam)
env = answer.get("env") if answer and answer.get("ok") else None
if not isinstance(env, dict):
@@ -1712,7 +1746,7 @@ def prepare_steam_ea(argv, compat_data, launch_dir):
except OSError as error:
log("steam ea: launcher not written (%s), left to the EA app" % type(error).__name__)
return 0
log("steam ea: %s starts %s directly as %s" % (manifest["title"], exe.name, answer.get("id") or offers[0]))
log("steam ea: %s starts %s directly as %s in %s" % (manifest["title"], exe.name, answer.get("id") or offers[0], locale))
return REPLACED
+42
View File
@@ -515,6 +515,7 @@ class SteamEa(unittest.TestCase):
with patch.dict(os.environ, env), patch.object(store, 'prepare_ea', side_effect=prepare):
self.assertEqual(store.REPLACED, store.main(['steam2ea://launchgame/1237970?platform=steam&theme=tf2']))
steam = asked[0][4]
self.assertEqual('en_US', steam['locale'])
self.assertEqual(['Origin.OFR.50.0001452', 'Origin.OFR.50.0001456'], steam['offers'])
self.assertEqual(['1039093'], steam['contentIds'])
self.assertEqual('Titanfall2.exe', steam['exe'])
@@ -532,6 +533,47 @@ class SteamEa(unittest.TestCase):
self.assertEqual(0, store.main(['--exited', 'steam2ea://launchgame/1237970']))
self.assertEqual([{'op': 'ea-exited', 'store': 'ea', 'id': 'Origin.OFR.50.0001452'}], asked)
def launch_locale(self, root, locales, appmanifest=None, steam_language=None):
folder, data = self.steam_copy(root)
if locales is not None:
text = MANIFEST.replace('<runtime>', '<installMetaData><locales>%s</locales></installMetaData>\n <runtime>' % locales)
(folder / '__Installer/installerdata.xml').write_bytes(b'\xff\xfe' + text.encode('utf-16-le'))
if appmanifest is not None:
(Path(root) / 'steamapps/appmanifest_1237970.acf').write_text(appmanifest)
asked = []
prepare = lambda *a: asked.append(a) or {'ok': False, 'reason': 'signed-out'}
env = {'STEAM_COMPAT_INSTALL_PATH': str(folder), 'STEAM_COMPAT_DATA_PATH': str(data), 'DD_LAUNCH_DIR': str(Path(root) / 'session')}
cleared = {k: v for k, v in os.environ.items() if k != 'DD_STEAM_LANGUAGE'}
if steam_language is not None:
cleared['DD_STEAM_LANGUAGE'] = steam_language
with patch.dict(os.environ, dict(cleared, **env), clear=True), patch.object(store, 'prepare_ea', side_effect=prepare):
store.main(['steam2ea://launchgame/1237970?platform=steam'])
self.assertEqual(asked[0][1]['extra']['locale'], asked[0][4]['locale'])
return asked[0][4]['locale']
def test_the_game_starts_in_the_language_steam_set_for_it(self):
acf = '"AppState"\n{\n\t"appid"\t\t"1237970"\n\t"UserConfig"\n\t{\n\t\t"language"\t\t"french"\n\t}\n}\n'
with tempfile.TemporaryDirectory() as root:
self.assertEqual('fr_FR', self.launch_locale(root, 'en_US,de_DE,fr_FR', acf, 'german'))
def test_without_a_language_for_the_game_steams_own_language_is_used(self):
with tempfile.TemporaryDirectory() as root:
self.assertEqual('de_DE', self.launch_locale(root, 'en_US,de_DE,fr_FR', None, 'german'))
def test_a_language_the_game_lacks_falls_back_to_english(self):
with tempfile.TemporaryDirectory() as root:
self.assertEqual('en_GB', self.launch_locale(root, 'en_GB,de_DE', None, 'french'))
with tempfile.TemporaryDirectory() as root:
self.assertEqual('en_US', self.launch_locale(root, None, None, 'french'))
with tempfile.TemporaryDirectory() as root:
self.assertEqual('en_US', self.launch_locale(root, 'en_US,fr_FR', None, None))
def test_the_locale_prefers_the_exact_regional_variant_then_the_same_language(self):
self.assertEqual('zh_HK', store.steam_ea_locale(['zh_CN', 'zh_HK'], 'tchinese'))
self.assertEqual('es_ES', store.steam_ea_locale(['en_US', 'es_ES'], 'latam'))
self.assertEqual('pt_BR', store.steam_ea_locale(['pt_PT', 'pt_BR'], 'brazilian'))
self.assertEqual('en_US', store.steam_ea_locale(['en_US', 'fr_FR'], 'unknown'))
def test_the_manifests_launch_parameters_keep_their_quotes(self):
with tempfile.TemporaryDirectory() as root:
folder, data = self.steam_copy(root)