@@ -483,6 +483,29 @@ QStringList MinecraftInstance::getNativeJars()
483483 return nativeJars;
484484}
485485
486+ static QString replaceTokensIn (const QString &text, const QMap<QString, QString> &with)
487+ {
488+ // TODO: does this still work??
489+ QString result;
490+ static const QRegularExpression s_token_regexp (" \\ $\\ {(.+)\\ }" , QRegularExpression::InvertedGreedinessOption);
491+ QStringList list;
492+ QRegularExpressionMatchIterator i = s_token_regexp.globalMatch (text);
493+ int lastCapturedEnd = 0 ;
494+ while (i.hasNext ()) {
495+ QRegularExpressionMatch match = i.next ();
496+ result.append (text.mid (lastCapturedEnd, match.capturedStart ()));
497+ QString key = match.captured (1 );
498+ auto iter = with.find (key);
499+ if (iter != with.end ()) {
500+ result.append (*iter);
501+ }
502+ lastCapturedEnd = match.capturedEnd ();
503+ }
504+ result.append (text.mid (lastCapturedEnd));
505+ return result;
506+ }
507+
508+
486509QStringList MinecraftInstance::extraArguments ()
487510{
488511 auto list = BaseInstance::extraArguments ();
@@ -495,7 +518,11 @@ QStringList MinecraftInstance::extraArguments()
495518 }
496519 auto addn = m_components->getProfile ()->getAddnJvmArguments ();
497520 if (!addn.isEmpty ()) {
498- list.append (addn);
521+ QMap<QString, QString> tokenMapping = makeProfileVarMapping (m_components->getProfile ());
522+
523+ for (const QString &item : addn) {
524+ list.append (replaceTokensIn (item, tokenMapping));
525+ }
499526 }
500527 auto agents = m_components->getProfile ()->getAgents ();
501528 for (auto agent : agents) {
@@ -705,28 +732,6 @@ QProcessEnvironment MinecraftInstance::createLaunchEnvironment()
705732 return env;
706733}
707734
708- static QString replaceTokensIn (QString text, QMap<QString, QString> with)
709- {
710- // TODO: does this still work??
711- QString result;
712- static const QRegularExpression s_token_regexp (" \\ $\\ {(.+)\\ }" , QRegularExpression::InvertedGreedinessOption);
713- QStringList list;
714- QRegularExpressionMatchIterator i = s_token_regexp.globalMatch (text);
715- int lastCapturedEnd = 0 ;
716- while (i.hasNext ()) {
717- QRegularExpressionMatch match = i.next ();
718- result.append (text.mid (lastCapturedEnd, match.capturedStart ()));
719- QString key = match.captured (1 );
720- auto iter = with.find (key);
721- if (iter != with.end ()) {
722- result.append (*iter);
723- }
724- lastCapturedEnd = match.capturedEnd ();
725- }
726- result.append (text.mid (lastCapturedEnd));
727- return result;
728- }
729-
730735QStringList MinecraftInstance::processMinecraftArgs (AuthSessionPtr session, MinecraftTarget::Ptr targetToJoin) const
731736{
732737 auto profile = m_components->getProfile ();
@@ -748,38 +753,27 @@ QStringList MinecraftInstance::processMinecraftArgs(AuthSessionPtr session, Mine
748753 }
749754 }
750755
751- QMap<QString, QString> token_mapping;
756+
757+ QMap<QString, QString> tokenMapping = makeProfileVarMapping (profile);
758+
752759 // yggdrasil!
753760 if (session) {
754761 // token_mapping["auth_username"] = session->username;
755- token_mapping[" auth_session" ] = session->session ;
756- token_mapping[" auth_access_token" ] = session->access_token ;
757- token_mapping[" auth_player_name" ] = session->player_name ;
758- token_mapping[" auth_uuid" ] = session->uuid ;
759- token_mapping[" user_properties" ] = session->serializeUserProperties ();
760- token_mapping[" user_type" ] = session->user_type ;
762+ tokenMapping[" auth_session" ] = session->session ;
763+ tokenMapping[" auth_access_token" ] = session->access_token ;
764+ tokenMapping[" auth_player_name" ] = session->player_name ;
765+ tokenMapping[" auth_uuid" ] = session->uuid ;
766+ tokenMapping[" user_properties" ] = session->serializeUserProperties ();
767+ tokenMapping[" user_type" ] = session->user_type ;
768+
761769 if (session->demo ) {
762770 args_pattern += " --demo" ;
763771 }
764772 }
765773
766- token_mapping[" profile_name" ] = name ();
767- token_mapping[" version_name" ] = profile->getMinecraftVersion ();
768- token_mapping[" version_type" ] = profile->getMinecraftVersionType ();
769-
770- QString absRootDir = QDir (gameRoot ()).absolutePath ();
771- token_mapping[" game_directory" ] = absRootDir;
772- QString absAssetsDir = QDir (" assets/" ).absolutePath ();
773- auto assets = profile->getMinecraftAssets ();
774- token_mapping[" game_assets" ] = AssetsUtils::getAssetsDir (assets->id , resourcesDir ()).absolutePath ();
775-
776- // 1.7.3+ assets tokens
777- token_mapping[" assets_root" ] = absAssetsDir;
778- token_mapping[" assets_index_name" ] = assets->id ;
779-
780774 QStringList parts = args_pattern.split (' ' , Qt::SkipEmptyParts);
781775 for (int i = 0 ; i < parts.length (); i++) {
782- parts[i] = replaceTokensIn (parts[i], token_mapping );
776+ parts[i] = replaceTokensIn (parts[i], tokenMapping );
783777 }
784778 return parts;
785779}
@@ -1024,6 +1018,29 @@ QMap<QString, QString> MinecraftInstance::createCensorFilterFromSession(AuthSess
10241018 return filter;
10251019}
10261020
1021+ QMap<QString, QString> MinecraftInstance::makeProfileVarMapping (std::shared_ptr<LaunchProfile> profile) const
1022+ {
1023+ QMap<QString, QString> result;
1024+
1025+ result[" profile_name" ] = name ();
1026+ result[" version_name" ] = profile->getMinecraftVersion ();
1027+ result[" version_type" ] = profile->getMinecraftVersionType ();
1028+
1029+ QString absRootDir = QDir (gameRoot ()).absolutePath ();
1030+ result[" game_directory" ] = absRootDir;
1031+ QString absAssetsDir = QDir (" assets/" ).absolutePath ();
1032+ auto assets = profile->getMinecraftAssets ();
1033+ result[" game_assets" ] = AssetsUtils::getAssetsDir (assets->id , resourcesDir ()).absolutePath ();
1034+
1035+ // 1.7.3+ assets tokens
1036+ result[" assets_root" ] = absAssetsDir;
1037+ result[" assets_index_name" ] = assets->id ;
1038+
1039+ result[" library_directory" ] = APPLICATION->metacache ()->getBasePath (" libraries" );
1040+
1041+ return result;
1042+ }
1043+
10271044QStringList MinecraftInstance::getLogFileSearchPaths ()
10281045{
10291046 return { FS::PathCombine (gameRoot (), " crash-reports" ), FS::PathCombine (gameRoot (), " logs" ), gameRoot () };
0 commit comments