88from typing import Any , Literal , TypeVar
99
1010import mobase
11- from PyQt6 .QtCore import QDateTime , QDir , qInfo
11+ from PyQt6 .QtCore import QDateTime , QDir , qCritical , qInfo , qWarning
1212
1313from ..basic_features import BasicLocalSavegames , BasicModDataChecker , GlobPatterns
1414from ..basic_features .basic_save_game_info import (
@@ -314,7 +314,7 @@ def apply(self) -> bool:
314314class Cyberpunk2077Game (BasicGame ):
315315 Name = "Cyberpunk 2077 Support Plugin"
316316 Author = "6788, Zash"
317- Version = "2.2.0 "
317+ Version = "2.2.1 "
318318
319319 GameName = "Cyberpunk 2077"
320320 GameShortName = "cyberpunk2077"
@@ -332,6 +332,7 @@ class Cyberpunk2077Game(BasicGame):
332332 )
333333
334334 _redmod_binary = Path ("tools/redmod/bin/redMod.exe" )
335+ _redmod_log = Path ("tools/redmod/bin/REDmodLog.txt" )
335336 _redmod_deploy_path = Path ("r6/cache/modded/" )
336337 _redmod_deploy_args = "deploy -reportProgress"
337338 """Deploy arguments for `redmod.exe`, -modlist=... is added."""
@@ -443,11 +444,17 @@ def executables(self) -> list[mobase.ExecutableInfo]:
443444 " -skipStartScreen" if self ._get_setting ("skipStartScreen" ) else ""
444445 )
445446 return [
447+ # Default, runs REDmod deploy if necessary
446448 mobase .ExecutableInfo (
447449 f"{ game_name } " ,
448450 bin_path ,
449451 ).withArgument (f"--launcher-skip -modded{ skip_start_screen } " ),
450- # Deploy REDmods
452+ # Start game without REDmod
453+ mobase .ExecutableInfo (
454+ f"{ game_name } - skip REDmod deploy" ,
455+ bin_path ,
456+ ).withArgument (f"--launcher-skip { skip_start_screen } " ),
457+ # Deploy REDmods only
451458 mobase .ExecutableInfo (
452459 "Manually deploy REDmod" ,
453460 self ._get_redmod_binary (),
@@ -478,36 +485,52 @@ def _onAboutToRun(self, app_path_str: str, wd: QDir, args: str) -> bool:
478485 modlist_param = f'-modlist="{ modlist_path } "' if modlist else ""
479486 args = f"{ args [:m .start ()]} { modlist_param } { args [m .end ():]} "
480487 qInfo (f"Manual modlist deployment: replacing { m [0 ]} , new args = { args } " )
481- self ._organizer .waitForApplication (
482- self ._organizer .startApplication (app_path_str , [args ], wd ), False
488+ self ._check_redmod_result (
489+ self ._organizer .waitForApplication (
490+ self ._organizer .startApplication (app_path_str , [args ], wd ),
491+ False ,
492+ )
483493 )
484- return False
485- return True # No recursive call
494+ return False # redmod with new args started
495+ return True # No recursive redmod call
486496 if (
487497 self ._get_setting ("auto_deploy_redmod" )
488498 and app_path == Path (self .gameDirectory ().absolutePath (), self .binaryName ())
489499 and "-modded" in args
490- and not self ._deploy_redmod ()
500+ and not self ._check_redmod_result ( self . _deploy_redmod () )
491501 ):
502+ qWarning ("Aborting game launch." )
492503 return False # Auto deploy failed
493504 self ._map_cache_files ()
494505 if self ._get_setting ("enforce_archive_load_order" ):
495506 self ._modlist_files .update_modlist ("archive" )
496507 return True
497508
498- def _deploy_redmod (self ) -> bool :
509+ def _check_redmod_result (self , result : tuple [bool , int ]) -> bool :
510+ if result == (True , 0 ):
511+ return True
512+ if result [1 ] < 0 :
513+ qWarning (f"REDmod deployment aborted (exit code { result [1 ]} )." )
514+ else :
515+ qCritical (
516+ f"REDmod deployment failed with exit code { result [1 ]} !"
517+ f" Check { Path ('GAME_FOLDER/' , self ._redmod_log )} "
518+ )
519+ return False
520+
521+ def _deploy_redmod (self ) -> tuple [bool , int ]:
499522 """Deploys redmod. Clears deployed files if no redmods are active.
500523 Recreates deployed files to force load order when necessary.
501524
502525 Returns:
503- False failed deployment, else True
526+ (success?, exit code)
504527 """
505528 # Add REDmod load order if none is specified
506529 redmod_list = list (self ._modlist_files .modfile_names ("redmod" ))
507530 if not redmod_list :
508531 qInfo ("Cleaning up redmod deployed files" )
509532 self ._clean_deployed_redmod ()
510- return True
533+ return True , 0
511534 args = self ._redmod_deploy_args
512535 if self ._get_setting ("enforce_redmod_load_order" ):
513536 modlist_path , _ , old_redmods = self ._modlist_files .update_modlist (
@@ -532,7 +555,7 @@ def _deploy_redmod(self) -> bool:
532555 redmod_binary , [args ], redmod_binary .parent
533556 ),
534557 False ,
535- )[ 0 ]
558+ )
536559
537560 def _clean_deployed_redmod (self , modlist_path : Path | None = None ):
538561 """Delete all files from `_redmod_deploy_path` except for `modlist_path`."""
0 commit comments