Skip to content

Commit

Permalink
Merge pull request #111 from unmojang/unmojang
Browse files Browse the repository at this point in the history
Merge develop -> unmojang, link to wiki page with common authlib-injector servers
  • Loading branch information
fn2006 authored Nov 15, 2023
2 parents 044980d + b1738de commit c5dad68
Show file tree
Hide file tree
Showing 14 changed files with 184 additions and 83 deletions.
16 changes: 15 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,19 @@
outputs = inputs:
inputs.flake-parts.lib.mkFlake
{inherit inputs;}
{imports = [./nix];};
{
imports = [
inputs.pre-commit-hooks.flakeModule

./nix/dev.nix
./nix/distribution.nix
];

systems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
};
}
2 changes: 1 addition & 1 deletion launcher/java/JavaUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ JavaInstallPtr JavaUtils::GetDefaultJava()

QStringList addJavasFromEnv(QList<QString> javas)
{
auto env = qEnvironmentVariable("PRISMLAUNCHER_JAVA_PATHS"); // FIXME: use launcher name from buildconfig
auto env = qEnvironmentVariable("POLLYMC_JAVA_PATHS"); // FIXME: use launcher name from buildconfig
#if defined(Q_OS_WIN32)
QList<QString> javaPaths = env.replace("\\", "/").split(QLatin1String(";"));

Expand Down
11 changes: 11 additions & 0 deletions launcher/minecraft/auth/AccountList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@ int AccountList::findAccountByProfileId(const QString& profileId) const
return -1;
}

MinecraftAccountPtr AccountList::getAccountByInternalId(const QString& accountId) const
{
for (int i = 0; i < count(); i++) {
MinecraftAccountPtr account = at(i);
if (account->internalId() == accountId) {
return account;
}
}
return nullptr;
}

MinecraftAccountPtr AccountList::getAccountByProfileName(const QString& profileName) const
{
for (int i = 0; i < count(); i++) {
Expand Down
1 change: 1 addition & 0 deletions launcher/minecraft/auth/AccountList.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class AccountList : public QAbstractListModel {
void addAccount(const MinecraftAccountPtr account);
void removeAccount(QModelIndex index);
int findAccountByProfileId(const QString& profileId) const;
MinecraftAccountPtr getAccountByInternalId(const QString& accountId) const;
MinecraftAccountPtr getAccountByProfileName(const QString& profileName) const;
QStringList profileNames() const;

Expand Down
2 changes: 2 additions & 0 deletions launcher/minecraft/auth/AuthSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ struct AuthSession {
bool uses_custom_api_servers = false;
QString authlib_injector_metadata;

// account ID
QString account_id;
// client token
QString client_token;
// account user name
Expand Down
2 changes: 2 additions & 0 deletions launcher/minecraft/auth/MinecraftAccount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,8 @@ void MinecraftAccount::fillSession(AuthSessionPtr session)
}
}

// account ID
session->account_id = internalId();
// the user name. you have to have an user name
// FIXME: not with MSA
session->username = data.userName();
Expand Down
2 changes: 1 addition & 1 deletion launcher/minecraft/launch/ClaimAccount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ClaimAccount::ClaimAccount(LaunchTask* parent, AuthSessionPtr session) : LaunchS
{
if (session->status == AuthSession::Status::PlayableOnline && !session->demo) {
auto accounts = APPLICATION->accounts();
m_account = accounts->getAccountByProfileName(session->player_name);
m_account = accounts->getAccountByInternalId(session->account_id);
}
}

Expand Down
5 changes: 4 additions & 1 deletion launcher/ui/dialogs/AuthlibInjectorLoginDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="userTextBox">
<property name="placeholderText">
<string>Email/username</string>
<string>Email/username</string>
</property>
</widget>
</item>
Expand Down
20 changes: 9 additions & 11 deletions launcher/ui/pages/global/AccountListPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@

#include "net/NetJob.h"

#include "ui/dialogs/AuthlibInjectorLoginDialog.h"
#include "ui/dialogs/CustomMessageBox.h"
#include "ui/dialogs/LoginDialog.h"
#include "ui/dialogs/AuthlibInjectorLoginDialog.h"
#include "ui/dialogs/MSALoginDialog.h"
#include "ui/dialogs/OfflineLoginDialog.h"
#include "ui/dialogs/ProgressDialog.h"
Expand Down Expand Up @@ -156,16 +156,14 @@ void AccountListPage::on_actionAddMojang_triggered()
void AccountListPage::on_actionAddAuthlibInjector_triggered()
{
MinecraftAccountPtr account = AuthlibInjectorLoginDialog::newAccount(
this,
tr(
"Please enter your username (sometimes an email address), password, and the URLs of your API servers."
"<br><br>"
"<b>Caution!</b> Your username and password will be sent to the authentication server you specify!"
)
);

if (account)
{
this, tr("Please enter your username (sometimes an email address), password, and the URL of your API server."
"<br>"
"See <a href=\"https://github.com/fn2006/PollyMC/wiki/Alternative-Auth-Servers\">this page</a> on the PollyMC wiki for a "
"list of common API servers.</p>"
"<br><br>"
"<b>Caution!</b> Your username and password will be sent to the authentication server you specify!"));

if (account) {
m_accounts->addAccount(account);
if (m_accounts->count() == 1) {
m_accounts->setDefaultAccount(account);
Expand Down
31 changes: 0 additions & 31 deletions nix/default.nix

This file was deleted.

38 changes: 17 additions & 21 deletions nix/dev.nix
Original file line number Diff line number Diff line change
@@ -1,37 +1,33 @@
{
inputs,
self,
...
}: {
perSystem = {
system,
config,
lib,
pkgs,
...
}: {
checks = {
pre-commit-check = inputs.pre-commit-hooks.lib.${system}.run {
src = self;
hooks = {
markdownlint.enable = true;
pre-commit.settings = {
hooks = {
markdownlint.enable = true;

alejandra.enable = true;
deadnix.enable = true;
nil.enable = true;
alejandra.enable = true;
deadnix.enable = true;
nil.enable = true;

clang-format = {
enable = true;
types_or = ["c" "c++" "java" "json" "objective-c"];
};
clang-format = {
enable = true;
types_or = ["c" "c++" "java" "json" "objective-c"];
};

tools.clang-tools = pkgs.clang-tools_16;
};

tools.clang-tools = lib.mkForce pkgs.clang-tools_16;
};

devShells.default = pkgs.mkShell {
inherit (self.checks.${system}.pre-commit-check) shellHook;
shellHook = ''
${config.pre-commit.installationScript}
'';

inputsFrom = [self.packages.${system}.prismlauncher-unwrapped];
inputsFrom = [config.packages.pollymc-unwrapped];
buildInputs = with pkgs; [ccache ninja];
};

Expand Down
46 changes: 30 additions & 16 deletions nix/distribution.nix
Original file line number Diff line number Diff line change
@@ -1,30 +1,44 @@
{
inputs,
self,
version,
...
}: {
perSystem = {pkgs, ...}: {
packages = {
inherit (pkgs) pollymc-qt5-unwrapped pollymc-qt5 pollymc-unwrapped pollymc;
default = pkgs.pollymc;
perSystem = {
lib,
pkgs,
...
}: {
packages = let
ourPackages = lib.fix (final: self.overlays.default ({inherit (pkgs) darwin;} // final) pkgs);
in {
inherit
(ourPackages)
pollymc-qt5-unwrapped
pollymc-qt5
pollymc-unwrapped
pollymc
;
default = ourPackages.pollymc;
};
};

flake = {
overlays.default = final: prev: let
# Helper function to build prism against different versions of Qt.
mkPrism = qt:
qt.callPackage ./package.nix {
inherit (inputs) libnbtplusplus;
inherit (prev.darwin.apple_sdk.frameworks) Cocoa;
inherit self version;
};
version = builtins.substring 0 8 self.lastModifiedDate or "dirty";

# common args for prismlauncher evaluations
unwrappedArgs = {
inherit (inputs) libnbtplusplus;
inherit (final.darwin.apple_sdk.frameworks) Cocoa;
inherit self version;
};
in {
pollymc-qt5-unwrapped = mkPrism final.libsForQt5;
pollymc-qt5 = prev.pollymc-qt5.override {pollymc-unwrapped = final.pollymc-qt5-unwrapped;};
pollymc-unwrapped = mkPrism final.qt6Packages;
pollymc = prev.pollymc.override {inherit (final) pollymc-unwrapped;};
pollymc-qt5-unwrapped = prev.libsForQt5.callPackage ./pkg unwrappedArgs;
pollymc-qt5 = prev.libsForQt5.callPackage ./pkg/wrapper.nix {
pollymc-unwrapped = final.pollymc-qt5-unwrapped;
};
pollymc-unwrapped = prev.qt6Packages.callPackage ./pkg unwrappedArgs;
pollymc = prev.qt6Packages.callPackage ./pkg/wrapper.nix {inherit (final) pollymc-unwrapped;};
};
};
}
File renamed without changes.
91 changes: 91 additions & 0 deletions nix/pkg/wrapper.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{
lib,
stdenv,
symlinkJoin,
pollymc-unwrapped,
wrapQtAppsHook,
qtbase, # needed for wrapQtAppsHook
qtsvg,
qtwayland,
xorg,
libpulseaudio,
libGL,
glfw,
openal,
jdk8,
jdk17,
gamemode,
flite,
mesa-demos,
udev,
msaClientID ? null,
gamemodeSupport ? stdenv.isLinux,
textToSpeechSupport ? stdenv.isLinux,
jdks ? [jdk17 jdk8],
additionalLibs ? [],
additionalPrograms ? [],
}: let
pollymcFinal = pollymc-unwrapped.override {
inherit msaClientID gamemodeSupport;
};
in
symlinkJoin {
name = "pollymc-${pollymcFinal.version}";

paths = [pollymcFinal];

nativeBuildInputs = [
wrapQtAppsHook
];

buildInputs =
[
qtbase
qtsvg
]
++ lib.optional (lib.versionAtLeast qtbase.version "6" && stdenv.isLinux) qtwayland;

postBuild = ''
wrapQtAppsHook
'';

qtWrapperArgs = let
runtimeLibs =
(with xorg; [
libX11
libXext
libXcursor
libXrandr
libXxf86vm
])
++ [
# lwjgl
libpulseaudio
libGL
glfw
openal
stdenv.cc.cc.lib

# oshi
udev
]
++ lib.optional gamemodeSupport gamemode.lib
++ lib.optional textToSpeechSupport flite
++ additionalLibs;

runtimePrograms =
[
xorg.xrandr
mesa-demos # need glxinfo
]
++ additionalPrograms;
in
["--prefix POLLYMC_JAVA_PATHS : ${lib.makeSearchPath "bin/java" jdks}"]
++ lib.optionals stdenv.isLinux [
"--set LD_LIBRARY_PATH /run/opengl-driver/lib:${lib.makeLibraryPath runtimeLibs}"
# xorg.xrandr needed for LWJGL [2.9.2, 3) https://github.com/LWJGL/lwjgl/issues/128
"--prefix PATH : ${lib.makeBinPath runtimePrograms}"
];

inherit (pollymcFinal) meta;
}

0 comments on commit c5dad68

Please sign in to comment.