Skip to content

Commit

Permalink
Use noFramework.
Browse files Browse the repository at this point in the history
To launch the game.
  • Loading branch information
cakihorse committed Jan 3, 2024
1 parent 03cd6c2 commit 0bd50e9
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 67 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ dependencies {
//dependencies to launch the game
implementation 'com.github.litarvan:openauth:518589d222'
implementation 'fr.flowarg:flowupdater:1.7.4'
implementation 'fr.flowarg:openlauncherlib:3.2.6'
implementation 'fr.flowarg:openlauncherlib:3.2.8'


//themes
Expand Down
65 changes: 28 additions & 37 deletions src/main/java/fr/cakihorse/swinglauncher/app/Launcher.java
Original file line number Diff line number Diff line change
@@ -1,37 +1,28 @@
package fr.cakihorse.swinglauncher.app;



import fr.cakihorse.swinglauncher.utils.Random;
import fr.flowarg.flowlogger.ILogger;
import fr.flowarg.flowlogger.Logger;
import fr.flowarg.flowupdater.FlowUpdater;
import fr.flowarg.flowupdater.download.IProgressCallback;
import fr.flowarg.flowupdater.download.json.MCP;
import fr.flowarg.flowupdater.versions.VanillaVersion;
import fr.theshark34.openlauncherlib.external.ExternalLaunchProfile;
import fr.theshark34.openlauncherlib.external.ExternalLauncher;
import fr.flowarg.openlauncherlib.NoFramework;
import fr.theshark34.openlauncherlib.minecraft.*;
import fr.theshark34.openlauncherlib.util.CrashReporter;
import fr.theshark34.openlauncherlib.minecraft.util.GameDirGenerator;

import java.awt.*;
import java.io.File;
import java.nio.file.Path;
import java.util.Arrays;


import static fr.cakihorse.swinglauncher.app.Main.getSaver;


public class Launcher extends Component {
private static GameInfos gameInfos = new GameInfos("launcherswing", new GameVersion("1.8.8", GameType.V1_8_HIGHER), new GameTweak[]{});
private static Path path = gameInfos.getGameDir();
public static File crashFile = new File(String.valueOf(path), "crashes");
private static CrashReporter cReporter = new CrashReporter(String.valueOf(crashFile), path);
//private static GameInfos gameInfos = new GameInfos("launcherswing", new GameVersion("1.8.8", GameType.V1_8_HIGHER), new GameTweak[]{});
private static final Path gameDir = GameDirGenerator.createGameDir("swinglauncher", false);
//private static Path gameDir = gameInfos.getGameDir();
static final ILogger logger = new Logger("[LAUNCHER]", null);
//private static CrashReporter cReporter = new CrashReporter(String.valueOf(crashFile), gameDir);
public static AuthInfos authInfos;
private static fr.cakihorse.swinglauncher.utils.Random Random;
private static IProgressCallback callback;






Expand All @@ -41,28 +32,33 @@ public static void update() throws Exception {
//keep this line if you have mcp !
.withName("1.8.8")
//with mcp :
// .withMCP(new MCP("YOUR_URL", Random.generateRandomString(10), 354254))
//.withMCP(new MCP("YOUR_URL", Random.generateRandomString(10), 354254))
//you can do a Random.generateRandomString for the sha1 but the client will be downloaded each restart.
.build();

final ILogger logger = new Logger("[LAUNCHER]", null);

//for more information about the update, join this discord : https://discord.gg/CS5NxapkDU
final FlowUpdater updater = new FlowUpdater.FlowUpdaterBuilder()
.withVanillaVersion(vanillaVersion)
.withLogger(logger)
.build();
updater.update(path);
updater.update(gameDir);
}

public static void launch() throws Exception {
//TODO: Use NoFramework to launch the game (if know how to do please PR this project)
ExternalLaunchProfile profile = MinecraftLauncher.createExternalProfile(gameInfos, GameFolder.FLOW_UPDATER, authInfos);
//add ram from saver to VMargs
profile.getVmArgs().addAll(Arrays.asList(new String[]{"-Xms2G", "-Xmx" + getSaver().get("ram") + "G"}));
ExternalLauncher launcher = new ExternalLauncher(profile);

//launch Minecraft
launcher.launch();
public static void launch() {
try {
NoFramework noFramework = new NoFramework(
gameDir,
authInfos,
GameFolder.FLOW_UPDATER
);
noFramework.getAdditionalVmArgs().add("-Xms1G");
noFramework.getAdditionalVmArgs().add("-Xmx" + getSaver().get("ram") + "G");

Process p = noFramework.launch("1.8.8", "",NoFramework.ModLoader.VANILLA);
} catch (Exception e) {
logger.printStackTrace(e);
}
}


Expand All @@ -75,12 +71,7 @@ public static void authCrack() {
authInfos = new AuthInfos(Random.generateRandomString(10), Random.generateRandomAccesToken(10),Random.generateRandomUUID());
}

public static Path getPath() {
return path;
public static Path getGameDir() {
return gameDir;
}

public static AuthInfos getAuthInfos() {
return authInfos;
}

}
46 changes: 22 additions & 24 deletions src/main/java/fr/cakihorse/swinglauncher/app/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,44 +21,43 @@

public class Main extends JFrame {

private static File saverFile = new File(String.valueOf(Launcher.getPath()), "user.infos");
private static Saver saver = new Saver(saverFile);
private static final File saverFile = new File(String.valueOf(Launcher.getGameDir()), "user.infos");
private static final Saver saver = new Saver(saverFile);
private int mouseX, mouseY;

public Main() throws IOException {

/*
* WARNING !
* This programme is gave but, the design must be changed !
* Only keep the "Back-end" of the app !
* (The design is only there because it has to be, please make it yours!)
* -------------------------------------------------
* To build the project with dependencies and make the jar executable use the
* Gradle task "shadowJar".
* -------------------------------------------------
* Author: Cakihorse.
*
*/


this.setTitle("Launcher V2");
* WARNING !
* This programme is gave but, the design must be changed !
* Only keep the "Back-end" of the app !
* (The design is only there because it has to be, please make it yours!)
* -------------------------------------------------
* To build the project with dependencies and make the jar executable use the
* Gradle task "shadowJar".
* -------------------------------------------------
* Author: Cakihorse.
*
*/


this.setTitle("SwingLauncher");
this.setSize(1280, 720);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setContentPane(new PCon(this));
this.setIconImage(new ImageIcon(Resources.getResource("logo.png")).getImage());
this.setResizable(false);

//verify if the user is connected
//Verify if the user is connected and change the panel if true
MicrosoftAuthenticator microsoftAuthenticator = new MicrosoftAuthenticator();
final String refresh_token = getSaver().get("refresh_token");
MicrosoftAuthResult result = null;
MicrosoftAuthResult result;

if (refresh_token != null && !refresh_token.isEmpty()) {
if (refresh_token != null) {
try {
result = microsoftAuthenticator.loginWithRefreshToken(refresh_token);
} catch (MicrosoftAuthenticationException ex) {

throw new RuntimeException(ex);
}
Launcher.authInfos = new AuthInfos(result.getProfile().getName(), result.getAccessToken(), result.getProfile().getId());
Expand Down Expand Up @@ -98,17 +97,16 @@ public void mouseDragged(MouseEvent e) {

public static void main(String[] args) throws IOException {
try {
//setuyo theme
//setup theme
FlatArcDarkIJTheme.setup();
} catch (Exception e) {
System.out.println("Erreur lors du chargement du thème");
e.printStackTrace();
Launcher.logger.printStackTrace(e);
}

//to launch the app
Main main = new Main();



}
public static Saver getSaver() {
return saver;
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/fr/cakihorse/swinglauncher/utils/Auth.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,21 @@

import static fr.cakihorse.swinglauncher.app.Main.getSaver;


public class Auth {

public static AuthInfos authInfos;


public static void launch() throws MicrosoftAuthenticationException, MalformedURLException {



if (getSaver().get("refresh_token") == null) {
MicrosoftAuthenticator microsoftAuthenticator = new MicrosoftAuthenticator();
final String refresh_token = getSaver().get("refresh_token");
MicrosoftAuthResult result = null;
if (refresh_token != null && !refresh_token.isEmpty()) {
if (refresh_token != null) {
result = microsoftAuthenticator.loginWithRefreshToken(refresh_token);
authInfos = new AuthInfos(result.getProfile().getName(), result.getAccessToken(), result.getProfile().getId());
Launcher.authInfos = new AuthInfos(result.getProfile().getName(), result.getAccessToken(), result.getProfile().getId());
System.out.printf("Logged in with '%s'%n", result.getProfile().getName());
} else {
result = microsoftAuthenticator.loginWithWebview();
Expand All @@ -34,7 +36,7 @@ public static void launch() throws MicrosoftAuthenticationException, MalformedUR
getSaver().set("clientToken", result.getClientId());

getSaver().save();
authInfos = new AuthInfos(result.getProfile().getName(), result.getAccessToken(), result.getProfile().getId());
Launcher.authInfos = new AuthInfos(result.getProfile().getName(), result.getAccessToken(), result.getProfile().getId());
System.out.printf("Logged in with '%s'%n", result.getProfile().getName());


Expand Down

0 comments on commit 0bd50e9

Please sign in to comment.