Skip to content

Commit

Permalink
added support for... 👀 - v1.09_13-pre3
Browse files Browse the repository at this point in the history
  • Loading branch information
Moresteck committed Apr 26, 2021
1 parent 7e900b2 commit 4ad6653
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 7 deletions.
1 change: 1 addition & 0 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src/main/app"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
<classpathentry kind="output" path="bin/default"/>
Expand Down
38 changes: 38 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,44 @@ jar {
}
}

task osxBuildApp {
dependsOn jar

doLast {
def dist = "${buildDir}/app/BetaCraft Launcher.app"
mkdir("$dist/Contents/MacOS")
mkdir("$dist/Contents/Resources")
copy {
from "${buildDir}/../src/main/app/Info.plist"
into "$dist/Contents"
}
copy {
from "${buildDir}/../src/main/app/PkgInfo"
into "$dist/Contents"
}
copy {
from "${buildDir}/../src/main/app/BetaCraft Launcher"
into "$dist/Contents/MacOS"
}
copy {
from "${buildDir}/../src/main/app/icon.icns"
into "$dist/Contents/Resources"
}
copy {
from "${buildDir}/libs/${project.name}.jar"
into "$dist/Contents/MacOS"
}
exec {
commandLine('rm', "${buildDir}/libs/BetaCraft-Launcher-macOS.zip")
commandLine("chmod", "+x", "$dist/Contents/MacOS/BetaCraft Launcher")
workingDir "${buildDir}/app/"
commandLine('zip', '-rvX', "../libs/BetaCraft-Launcher-macOS.zip", '.')
}
}
}

build.dependsOn osxBuildApp

configurations {
extraLibs
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/app/BetaCraft Launcher
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

DIR=$(cd "$(dirname "$0")"; pwd)

exec java -Xdock:name="BetaCraft Launcher" -Xdock:icon="$DIR/../Resources/icon.icns" -cp ".;$DIR;" -jar "$DIR/BetaCraft-Launcher-Java.jar"
37 changes: 37 additions & 0 deletions src/main/app/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>BetaCraft Launcher</string>
<key>CFBundleIconFile</key>
<string>icon.icns</string>
<key>CFBundleIdentifier</key>
<string>pl.betacraft.launcher</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>BetaCraft Launcher</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.games</string>
<key>LSMinimumSystemVersion</key>
<string>10.8.5</string>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>NSMainStoryboardFile</key>
<string>Main</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
</dict>
</plist>
1 change: 1 addition & 0 deletions src/main/app/PkgInfo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
APPL????
Binary file added src/main/app/icon.icns
Binary file not shown.
23 changes: 21 additions & 2 deletions src/main/java/org/betacraft/Classic12aWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.awt.event.MouseListener;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;

Expand Down Expand Up @@ -162,7 +163,12 @@ public void stop() {
runningField.set(run, false);
}
}
clazz.getDeclaredMethod("stop", null).invoke(run);
Method real12a = clazz.getDeclaredMethod("a", null);
if (real12a == null) {
// 12a-dev
real12a = clazz.getDeclaredMethod("stop", null);
}
real12a.invoke(run);
}
}
} catch (Exception ex) {
Expand All @@ -186,7 +192,12 @@ public void destroy() {
if (name.contains("mojang")) {
final Class<?> clazz = classLoader.loadClass(name);
mcField.setAccessible(true);
clazz.getDeclaredMethod("destroy", null).invoke(run);
Method real12a = clazz.getDeclaredMethod("a", null);
if (real12a == null) {
// 12a-dev
real12a = clazz.getDeclaredMethod("destroy", null);
}
real12a.invoke(run);
}
}
}
Expand All @@ -201,6 +212,14 @@ public void destroy() {

public void setResolution(Runnable run, Canvas canvas, Class<?> clazz) {
try {
for (Field widthHeightField : clazz.getDeclaredFields()) {
if (widthHeightField.getName().equals("a")) {
widthHeightField.set(run, panel.getWidth());
}
if (widthHeightField.getName().equals("b")) {
widthHeightField.set(run, panel.getHeight());
}
}
for (final Field appletModeField : clazz.getDeclaredFields()) {
if (appletModeField.getType().getName().equalsIgnoreCase("boolean") && Modifier.isPublic(appletModeField.getModifiers())) {
appletModeField.setAccessible(true);
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/org/betacraft/Wrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
import java.applet.Applet;
import java.applet.AppletStub;
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowAdapter;
Expand Down Expand Up @@ -709,4 +706,11 @@ public String getParameter(final String paramName) {
}
return null;
}

// Backwards compatibility, eh
public class BCClassLoader extends URLClassLoader {
public BCClassLoader(URL[] urls) {
super(urls);
}
}
}
11 changes: 11 additions & 0 deletions src/main/java/org/betacraft/launcher/Instance.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.betacraft.launcher;

import java.awt.Image;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
Expand Down Expand Up @@ -145,6 +146,16 @@ public Instance clone(String name) {
return cloned;
}

public String getIconLocation() throws IOException {
File imgFile = new File(BC.get() + "launcher" + File.separator + "instances", this.name + ".png");
File defaultImg = new File(BC.get() + "launcher" + File.separator + "default_icon.png");
if (!imgFile.exists()) {
Files.copy(this.getClass().getClassLoader().getResourceAsStream("icons/favicon.png"), defaultImg.toPath(), StandardCopyOption.REPLACE_EXISTING);
return defaultImg.toPath().toString();
}
return imgFile.toPath().toString();
}

public Image getIcon() {
try {
File imgFile = new File(BC.get() + "launcher" + File.separator + "instances", this.name + ".png");
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/org/betacraft/launcher/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

/** Main class */
public class Launcher {
public static String VERSION = "1.09_13-pre2"; // TODO Always update this
public static String VERSION = "1.09_13-pre3"; // TODO Always update this

public static Instance currentInstance;
public static boolean forceUpdate = false;
Expand All @@ -60,7 +60,7 @@ public class Launcher {
public static Accounts accounts = new Accounts();

public static void main(String[] args) {
System.out.println("Java version: " + System.getProperty("java.vendor") + ", " + System.getProperty("java.runtime.name") + ", " + System.getProperty("java.runtime.version"));
System.err.println("Java version: " + System.getProperty("java.vendor") + ", " + System.getProperty("java.runtime.name") + ", " + System.getProperty("java.runtime.version"));
long nano = System.nanoTime();
try {
// Fix for Java having a cross-platform look and feel
Expand Down Expand Up @@ -511,6 +511,11 @@ public boolean accept(File dir, String fileName) {
params.add("-Dbetacraft.ask_for_server=true");
}

if (OS.isMac()) {
params.add("-Xdock:name=" + instance.name);
params.add("-Xdock:icon=" + instance.getIconLocation());
}

// Add custom parameters from options
if (instance.launchArgs != null && !instance.launchArgs.equals("")) {
params.addAll(getCustomParameters());
Expand Down

0 comments on commit 4ad6653

Please sign in to comment.