from pathlib import Path import sys,os,json,subprocess,time,fcntl,shutil ROOT=Path('/home/jakub/devel/escapistsrereintroduced');sys.path.insert(0,str(ROOT/'tools')) from headless_game import assert_prefix_idle,cleanup_owned_run from external_addons import policy,prepare_profile steam=Path.home()/'.local/share/Steam';compat=Path('/tmp/erri-headless-compat');profile=Path('/tmp/erri-takeover-nogova1');profile.mkdir() lock=(compat/'.erri-workbench.lock').open('a');fcntl.flock(lock,fcntl.LOCK_EX|fcntl.LOCK_NB);assert_prefix_idle(compat) addons=profile/'addons';addons.mkdir() external=steam/'steamapps/compatdata/1874880/pfx/drive_c/users/steamuser/Documents/My Games/ArmaReforger/addons' prepare_profile(addons,external,policy(ROOT),profile/'external-cache.json') for name,target in [('ArmaReforger',steam/'steamapps/common/Arma Reforger/addons/data'),('ERR_Core',Path('/tmp/erri-takeover-source1')),('Nogova',Path('/home/jakub/devel/gabreta/addons/NogovaReforger'))]: (addons/name).symlink_to(target,target_is_directory=True) config={'bindAddress':'127.0.0.1','bindPort':22991,'game':{'name':'Private terrain header probe','password':'private-local-probe','scenarioId':'{469880DFE1B48F95}Missions/Nogova_TerrainTest.conf','maxPlayers':1,'visible':False,'supportedPlatforms':['PLATFORM_PC'],'gameProperties':{'battlEye':False,'missionHeader':{'World':'{52BA23DC05308E33}Worlds/Nogova/Nogova.ent'}}}} (profile/'server.json').write_text(json.dumps(config,indent=2)) proton=steam/'steamapps/common/Proton - Experimental/proton';game=steam/'steamapps/common/Arma Reforger' cmd=['gamescope','--backend','headless','-W','1280','-H','720','-w','1280','-h','720','-r','30','--',str(proton),'run',str(game/'ArmaReforgerSteamDiag.exe'),'-server','{469880DFE1B48F95}Missions/Nogova_TerrainTest.conf','-config','Z:'+str(profile/'server.json'),'-addonsDir','Z:'+str(addons),'-addons','2528466DE220D91C,70C981A53E02B64F','-profile','Z:'+str(profile),'-noBackend','-bindIP','127.0.0.1','-bindPort','22991','-errTerrainTakeover','1','-maxFPS','30','-logconsole','-noSound','-noSplash','-noThrow','-disableCrashReporter'] env=os.environ.copy();env.update(STEAM_COMPAT_DATA_PATH=str(compat),STEAM_COMPAT_CLIENT_INSTALL_PATH=str(steam),WINEPREFIX=str(compat/'pfx'),PULSE_SINK='erri_tests_silent') (profile/'command.json').write_text(json.dumps(cmd,indent=2)) child=None;started=time.time() with (profile/'launch.log').open('w') as log: try: child=subprocess.Popen(cmd,cwd=game,env=env,stdout=log,stderr=subprocess.STDOUT,start_new_session=True) while time.time()-started<240 and child.poll() is None: sessions=sorted((profile/'logs').glob('logs_*/console.log')) if sessions: text=sessions[-1].read_text(errors='replace') if 'Reintroduced [spawn]: player ' in text or 'scenario preparation failed' in text or 'Unable to initialize the game' in text:break time.sleep(1) finally: if child: report=cleanup_owned_run(child,proton,env,compat);(profile/'cleanup.json').write_text(json.dumps(report,indent=2));print(report) print(profile)