From 7179e75e70f4157326d6d97f11a947df576d02e6 Mon Sep 17 00:00:00 2001 From: Graeme Geldenhuys Date: Sun, 12 Dec 2021 00:35:46 +0000 Subject: Changes required to support FreeBSD --- launcher/minecraft/launch/ExtractNatives.cpp | 7 ++++ launcher/minecraft/launch/PrintInstanceInfo.cpp | 45 +++++++++++++++++++++++-- 2 files changed, 50 insertions(+), 2 deletions(-) (limited to 'launcher/minecraft/launch') diff --git a/launcher/minecraft/launch/ExtractNatives.cpp b/launcher/minecraft/launch/ExtractNatives.cpp index d57499aa..8cd439b1 100644 --- a/launcher/minecraft/launch/ExtractNatives.cpp +++ b/launcher/minecraft/launch/ExtractNatives.cpp @@ -23,6 +23,13 @@ #include "FileSystem.h" #include +#ifdef major + #undef major +#endif +#ifdef minor + #undef minor +#endif + static QString replaceSuffix (QString target, const QString &suffix, const QString &replacement) { if (!target.endsWith(suffix)) diff --git a/launcher/minecraft/launch/PrintInstanceInfo.cpp b/launcher/minecraft/launch/PrintInstanceInfo.cpp index 3da17902..e8fbcb9b 100644 --- a/launcher/minecraft/launch/PrintInstanceInfo.cpp +++ b/launcher/minecraft/launch/PrintInstanceInfo.cpp @@ -19,8 +19,9 @@ #include "PrintInstanceInfo.h" #include -#ifdef Q_OS_LINUX +#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) namespace { +#if defined(Q_OS_LINUX) void probeProcCpuinfo(QStringList &log) { std::ifstream cpuin("/proc/cpuinfo"); @@ -66,7 +67,43 @@ void runLspci(QStringList &log) } pclose(lspci); } +#elif defined(Q_OS_FREEBSD) +void runSysctlHwModel(QStringList &log) +{ + char buff[512]; + FILE *hwmodel = popen("sysctl hw.model", "r"); + while (fgets(buff, 512, hwmodel) != NULL) + { + log << QString::fromUtf8(buff); + break; + } + pclose(hwmodel); +} +void runPciconf(QStringList &log) +{ + char buff[512]; + std::string strcard; + FILE *pciconf = popen("pciconf -lv -a vgapci0", "r"); + while (fgets(buff, 512, pciconf) != NULL) + { + if (strncmp(buff, " vendor", 10) == 0) + { + std::string str(buff); + strcard.append(str.substr(str.find_first_of("'") + 1, str.find_last_not_of("'") - (str.find_first_of("'") + 2))); + strcard.append(" "); + } + else if (strncmp(buff, " device", 10) == 0) + { + std::string str2(buff); + strcard.append(str2.substr(str2.find_first_of("'") + 1, str2.find_last_not_of("'") - (str2.find_first_of("'") + 2))); + } + log << QString::fromStdString(strcard); + break; + } + pclose(pciconf); +} +#endif void runGlxinfo(QStringList & log) { // FIXME: fixed size buffers... @@ -94,10 +131,14 @@ void PrintInstanceInfo::executeTask() auto instance = m_parent->instance(); QStringList log; -#ifdef Q_OS_LINUX +#if defined(Q_OS_LINUX) ::probeProcCpuinfo(log); ::runLspci(log); ::runGlxinfo(log); +#elif defined(Q_OS_FREEBSD) + ::runSysctlHwModel(log); + ::runPciconf(log); + ::runGlxinfo(log); #endif logLines(log, MessageLevel::Launcher); -- cgit From fce98f5e166d20930d71168b967aab3bb2cab82b Mon Sep 17 00:00:00 2001 From: Graeme Geldenhuys Date: Sun, 12 Dec 2021 11:45:58 +0000 Subject: Fixes compilation error expanding from macro 'major'. --- launcher/minecraft/launch/VerifyJavaInstall.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'launcher/minecraft/launch') diff --git a/launcher/minecraft/launch/VerifyJavaInstall.cpp b/launcher/minecraft/launch/VerifyJavaInstall.cpp index d9f7ecdc..15acf678 100644 --- a/launcher/minecraft/launch/VerifyJavaInstall.cpp +++ b/launcher/minecraft/launch/VerifyJavaInstall.cpp @@ -5,6 +5,13 @@ #include #include +#ifdef major + #undef major +#endif +#ifdef minor + #undef minor +#endif + void VerifyJavaInstall::executeTask() { auto m_inst = std::dynamic_pointer_cast(m_parent->instance()); -- cgit From 94fdf13f4a113bb1ffc75a4862308f12c904b2c4 Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Thu, 30 Dec 2021 21:26:29 +0100 Subject: NOISSUE proper fix for missing profile + demo mode --- launcher/LaunchController.cpp | 63 +++++++++++++++++------------- launcher/minecraft/MinecraftInstance.cpp | 10 +++-- launcher/minecraft/auth/AuthSession.cpp | 5 +++ launcher/minecraft/auth/AuthSession.h | 4 ++ launcher/minecraft/auth/Parsers.cpp | 2 +- launcher/minecraft/launch/ClaimAccount.cpp | 2 +- 6 files changed, 54 insertions(+), 32 deletions(-) (limited to 'launcher/minecraft/launch') diff --git a/launcher/LaunchController.cpp b/launcher/LaunchController.cpp index be12eb79..7750be1a 100644 --- a/launcher/LaunchController.cpp +++ b/launcher/LaunchController.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include "BuildConfig.h" #include "JavaCommon.h" @@ -145,36 +146,44 @@ void LaunchController::login() { m_session->MakeOffline(usedname); // offline flavored game from here :3 } - if(m_accountToUse->ownsMinecraft() && !m_accountToUse->hasProfile()) { - auto entitlement = m_accountToUse->accountData()->minecraftEntitlement; - QString errorString; - if(!entitlement.canPlayMinecraft) { - errorString = tr("The account does not own Minecraft. You need to purchase the game first to play it."); - QMessageBox::warning( - nullptr, - tr("Missing Minecraft profile"), - errorString, - QMessageBox::StandardButton::Ok, - QMessageBox::StandardButton::Ok - ); - emitFailed(errorString); - return; - } - // Now handle setting up a profile name here... - ProfileSetupDialog dialog(m_accountToUse, m_parentWidget); - if (dialog.exec() == QDialog::Accepted) - { - tryagain = true; - continue; - } - else - { - emitFailed(tr("Received undetermined session status during login.")); - return; + if(m_accountToUse->ownsMinecraft()) { + if(!m_accountToUse->hasProfile()) { + // Now handle setting up a profile name here... + ProfileSetupDialog dialog(m_accountToUse, m_parentWidget); + if (dialog.exec() == QDialog::Accepted) + { + tryagain = true; + continue; + } + else + { + emitFailed(tr("Received undetermined session status during login.")); + return; + } } + // we own Minecraft, there is a profile, it's all ready to go! + launchInstance(); + return; } else { - launchInstance(); + // play demo ? + QMessageBox box(m_parentWidget); + box.setWindowTitle(tr("Play demo?")); + box.setText(tr("This account does not own Minecraft.\nYou need to purchase the game first to play it.\n\nDo you want to play the demo?")); + box.setIcon(QMessageBox::Warning); + auto demoButton = box.addButton(tr("Play Demo"), QMessageBox::ButtonRole::YesRole); + auto cancelButton = box.addButton(tr("Cancel"), QMessageBox::ButtonRole::NoRole); + box.setDefaultButton(cancelButton); + + box.exec(); + if(box.clickedButton() == demoButton) { + // play demo here + m_session->MakeDemo(); + launchInstance(); + } + else { + emitFailed(tr("Launch cancelled - account does not own Minecraft.")); + } } return; } diff --git a/launcher/minecraft/MinecraftInstance.cpp b/launcher/minecraft/MinecraftInstance.cpp index 2526e620..0b3c049b 100644 --- a/launcher/minecraft/MinecraftInstance.cpp +++ b/launcher/minecraft/MinecraftInstance.cpp @@ -431,8 +431,7 @@ QStringList MinecraftInstance::processMinecraftArgs( QMap token_mapping; // yggdrasil! - if(session) - { + if(session) { // token_mapping["auth_username"] = session->username; token_mapping["auth_session"] = session->session; token_mapping["auth_access_token"] = session->access_token; @@ -440,6 +439,9 @@ QStringList MinecraftInstance::processMinecraftArgs( token_mapping["auth_uuid"] = session->uuid; token_mapping["user_properties"] = session->serializeUserProperties(); token_mapping["user_type"] = session->user_type; + if(session->demo) { + args_pattern += " --demo"; + } } // blatant self-promotion. @@ -872,7 +874,9 @@ shared_qobject_ptr MinecraftInstance::createLaunchTask(AuthSessionPt // if we aren't in offline mode,. if(session->status != AuthSession::PlayableOffline) { - process->appendStep(new ClaimAccount(pptr, session)); + if(!session->demo) { + process->appendStep(new ClaimAccount(pptr, session)); + } process->appendStep(new Update(pptr, Net::Mode::Online)); } else diff --git a/launcher/minecraft/auth/AuthSession.cpp b/launcher/minecraft/auth/AuthSession.cpp index d44f9098..6bea74a3 100644 --- a/launcher/minecraft/auth/AuthSession.cpp +++ b/launcher/minecraft/auth/AuthSession.cpp @@ -30,3 +30,8 @@ bool AuthSession::MakeOffline(QString offline_playername) status = PlayableOffline; return true; } + +void AuthSession::MakeDemo() { + player_name = "Player"; + demo = true; +} diff --git a/launcher/minecraft/auth/AuthSession.h b/launcher/minecraft/auth/AuthSession.h index 55fbdf39..a75df506 100644 --- a/launcher/minecraft/auth/AuthSession.h +++ b/launcher/minecraft/auth/AuthSession.h @@ -11,6 +11,7 @@ class QNetworkAccessManager; struct AuthSession { bool MakeOffline(QString offline_playername); + void MakeDemo(); QString serializeUserProperties(); @@ -43,6 +44,9 @@ struct AuthSession bool auth_server_online = false; // Did the user request online mode? bool wants_online = true; + + //Is this a demo session? + bool demo = false; }; typedef std::shared_ptr AuthSessionPtr; diff --git a/launcher/minecraft/auth/Parsers.cpp b/launcher/minecraft/auth/Parsers.cpp index 2b189fe4..ed31e934 100644 --- a/launcher/minecraft/auth/Parsers.cpp +++ b/launcher/minecraft/auth/Parsers.cpp @@ -227,7 +227,7 @@ bool parseMinecraftEntitlements(QByteArray & data, MinecraftEntitlement &output) auto obj = doc.object(); output.canPlayMinecraft = false; - output.ownsMinecraft = true; + output.ownsMinecraft = false; auto itemsArray = obj.value("items").toArray(); for(auto item: itemsArray) { diff --git a/launcher/minecraft/launch/ClaimAccount.cpp b/launcher/minecraft/launch/ClaimAccount.cpp index bb4f6806..1cd7c0da 100644 --- a/launcher/minecraft/launch/ClaimAccount.cpp +++ b/launcher/minecraft/launch/ClaimAccount.cpp @@ -6,7 +6,7 @@ ClaimAccount::ClaimAccount(LaunchTask* parent, AuthSessionPtr session): LaunchStep(parent) { - if(session->status == AuthSession::Status::PlayableOnline) + if(session->status == AuthSession::Status::PlayableOnline && !session->demo) { auto accounts = APPLICATION->accounts(); m_account = accounts->getAccountByProfileName(session->player_name); -- cgit