Compare commits

..
Author SHA1 Message Date
artdeell 81c6813a6b Fix[nativesextractor]: improve style, address performance/debuggability concerns 2025-02-15 18:33:54 +03:00
artdeell d713fe52ea Feat[mc_downloader]: native library downloading and extraction
Currently implemented only for JNA
2025-02-14 17:56:20 +03:00
artdeell 92bde837fd Feat[mod_fragment]: remove explicit static variable in each mod install fragment 2025-02-10 22:48:17 +03:00
artdeell 1e060d1aa8 Style[bta_adapter]: change return types 2025-02-10 22:48:17 +03:00
artdeell fab0186cbe Style[bta_profile]: add clarifying comments 2025-02-10 22:48:17 +03:00
artdeell 988d3bbcb6 Style[bta_profile]: improve code niceness 2025-02-10 22:48:17 +03:00
artdeell 9e53552a8c Feat[bta_profile]: add the ability to install nightlies 2025-02-10 22:48:17 +03:00
artdeell 740568fafa Fix[bta_profile]: set custom game directory 2025-02-10 22:48:17 +03:00
artdeell 4903cfc8d3 Feat[launcher]: add support for the "Better than Adventure!" mod 2025-02-10 22:48:17 +03:00
Maksim Belov 21cfcdb15e Feat[input]: GLFW direct controller input (#6604) 2025-02-07 18:35:52 +03:00
artdeell ffc74c502a Fix[downloader]: fix size fetching 2025-02-07 18:35:11 +03:00
artdeell 4e1bdd8675 Fix[lwjgl]: update OpenAL to fix issues with soundfilters and other mods
Reference: https://github.com/PojavLauncherTeam/lwjgl3/pull/7
2025-02-05 22:28:56 +03:00
artdeell 0ee0dfecc2 Fix[glfw]: stubs for getMonitorContentScale 2025-02-04 18:47:03 +03:00
Maksim Belov 5a98a43d21 Merge pull request #6599 from PojavLauncherTeam/feat/true_display_create_state
Feat/true display create state
2025-02-04 18:40:07 +03:00
27 changed files with 502 additions and 46 deletions

No files matched your search

@@ -1 +1 @@
1687691695196
1738839797928
@@ -1 +1 @@
1692525087345
1738839797913
@@ -1 +1 @@
1732218529630
1738839797921
@@ -29,6 +29,8 @@ import androidx.annotation.RequiresApi;
import net.kdt.pojavlaunch.customcontrols.ControlLayout;
import net.kdt.pojavlaunch.customcontrols.gamepad.DefaultDataProvider;
import net.kdt.pojavlaunch.customcontrols.gamepad.Gamepad;
import net.kdt.pojavlaunch.customcontrols.gamepad.direct.DirectGamepad;
import net.kdt.pojavlaunch.customcontrols.gamepad.direct.DirectGamepadEnableHandler;
import net.kdt.pojavlaunch.customcontrols.mouse.AbstractTouchpad;
import net.kdt.pojavlaunch.customcontrols.mouse.AndroidPointerCapture;
import net.kdt.pojavlaunch.customcontrols.mouse.InGUIEventProcessor;
@@ -40,15 +42,16 @@ import net.kdt.pojavlaunch.utils.MCOptionUtils;
import org.lwjgl.glfw.CallbackBridge;
import fr.spse.gamepad_remapper.GamepadHandler;
import fr.spse.gamepad_remapper.RemapperManager;
import fr.spse.gamepad_remapper.RemapperView;
/**
* Class dealing with showing minecraft surface and taking inputs to dispatch them to minecraft
*/
public class MinecraftGLSurface extends View implements GrabListener {
public class MinecraftGLSurface extends View implements GrabListener, DirectGamepadEnableHandler {
/* Gamepad object for gamepad inputs, instantiated on need */
private Gamepad mGamepad = null;
private GamepadHandler mGamepadHandler;
/* The RemapperView.Builder object allows you to set which buttons to remap */
private final RemapperManager mInputManager = new RemapperManager(getContext(), new RemapperView.Builder(null)
.remapA(true)
@@ -88,6 +91,7 @@ public class MinecraftGLSurface extends View implements GrabListener {
public MinecraftGLSurface(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
setFocusable(true);
CallbackBridge.setDirectGamepadEnableHandler(this);
}
@RequiresApi(api = Build.VERSION_CODES.O)
@@ -203,7 +207,11 @@ public class MinecraftGLSurface extends View implements GrabListener {
}
private void createGamepad(View contextView, InputDevice inputDevice) {
mGamepad = new Gamepad(contextView, inputDevice, DefaultDataProvider.INSTANCE, true);
if(CallbackBridge.sGamepadDirectInput) {
mGamepadHandler = new DirectGamepad();
}else {
mGamepadHandler = new Gamepad(contextView, inputDevice, DefaultDataProvider.INSTANCE, true);
}
}
/**
@@ -215,9 +223,9 @@ public class MinecraftGLSurface extends View implements GrabListener {
int mouseCursorIndex = -1;
if(Gamepad.isGamepadEvent(event)){
if(mGamepad == null) createGamepad(this, event.getDevice());
if(mGamepadHandler == null) createGamepad(this, event.getDevice());
mInputManager.handleMotionEventInput(getContext(), event, mGamepad);
mInputManager.handleMotionEventInput(getContext(), event, mGamepadHandler);
return true;
}
@@ -287,9 +295,9 @@ public class MinecraftGLSurface extends View implements GrabListener {
}
if(Gamepad.isGamepadEvent(event)){
if(mGamepad == null) createGamepad(this, event.getDevice());
if(mGamepadHandler == null) createGamepad(this, event.getDevice());
mInputManager.handleKeyEventInput(getContext(), event, mGamepad);
mInputManager.handleKeyEventInput(getContext(), event, mGamepadHandler);
return true;
}
@@ -411,6 +419,17 @@ public class MinecraftGLSurface extends View implements GrabListener {
}
}
@Override
public void onDirectGamepadEnabled() {
post(()->{
if(mGamepadHandler != null && mGamepadHandler instanceof Gamepad) {
((Gamepad)mGamepadHandler).removeSelf();
}
// Force gamepad recreation on next event
mGamepadHandler = null;
});
}
/** A small interface called when the listener is ready for the first time */
public interface SurfaceReadyListener {
void isReady();
@@ -325,6 +325,14 @@ public final class Tools {
}
javaArgList.add("-Dlog4j.configurationFile=" + configFile);
}
File versionSpecificNativesDir = new File(Tools.DIR_CACHE, "natives/"+versionId);
if(versionSpecificNativesDir.exists()) {
String dirPath = versionSpecificNativesDir.getAbsolutePath();
javaArgList.add("-Djava.library.path="+dirPath+":"+Tools.NATIVE_LIB_DIR);
javaArgList.add("-Djna.boot.library.path="+dirPath);
}
javaArgList.addAll(Arrays.asList(getMinecraftJVMArgs(versionId, gamedir)));
javaArgList.add("-cp");
javaArgList.add(launchClassPath + ":" + getLWJGL3ClassPath());
@@ -30,4 +30,9 @@ public class DefaultDataProvider implements GamepadDataProvider {
public void attachGrabListener(GrabListener grabListener) {
CallbackBridge.addGrabListener(grabListener);
}
@Override
public void detachGrabListener(GrabListener grabListener) {
CallbackBridge.removeGrabListener(grabListener);
}
}
@@ -26,7 +26,6 @@ import androidx.core.math.MathUtils;
import net.kdt.pojavlaunch.GrabListener;
import net.kdt.pojavlaunch.LwjglGlfwKeycode;
import net.kdt.pojavlaunch.R;
import net.kdt.pojavlaunch.prefs.LauncherPreferences;
import net.kdt.pojavlaunch.utils.MCOptionUtils;
import org.lwjgl.glfw.CallbackBridge;
@@ -88,6 +87,8 @@ public class Gamepad implements GrabListener, GamepadHandler {
private final GamepadDataProvider mMapProvider;
private boolean mRemoved = false;
public Gamepad(View contextView, InputDevice inputDevice, GamepadDataProvider mapProvider, boolean showCursor){
Settings.setDeadzoneScale(PREF_DEADZONE_SCALE);
@@ -96,7 +97,7 @@ public class Gamepad implements GrabListener, GamepadHandler {
@Override
public void doFrame(long frameTimeNanos) {
tick(frameTimeNanos);
mScreenChoreographer.postFrameCallback(this);
if(!mRemoved) mScreenChoreographer.postFrameCallback(this);
}
};
mScreenChoreographer.postFrameCallback(frameCallback);
@@ -453,4 +454,15 @@ public class Gamepad implements GrabListener, GamepadHandler {
break;
}
}
/**
* Stops the Gamepad and removes all traces of the Gamepad from the view hierarchy.
* After this call, the Gamepad is not recoverable and a new one must be made.
*/
public void removeSelf() {
mRemoved = true;
mMapProvider.detachGrabListener(this);
ViewGroup viewGroup = (ViewGroup) mPointerImageView.getParent();
if(viewGroup != null) viewGroup.removeView(mPointerImageView);
}
}
@@ -7,4 +7,5 @@ public interface GamepadDataProvider {
GamepadMap getGameMap();
boolean isGrabbing();
void attachGrabListener(GrabListener grabListener);
void detachGrabListener(GrabListener grabListener);
}
@@ -325,6 +325,11 @@ public class GamepadMapperAdapter extends RecyclerView.Adapter<GamepadMapperAdap
grabListener.onGrabState(mGrabState);
}
@Override
public void detachGrabListener(GrabListener grabListener) {
mGamepadGrabListener = null;
}
public void setGrabState(boolean newState) {
mGrabState = newState;
if(mGamepadGrabListener != null) mGamepadGrabListener.onGrabState(newState);
@@ -0,0 +1,78 @@
package net.kdt.pojavlaunch.customcontrols.gamepad.direct;
import static org.lwjgl.glfw.CallbackBridge.sGamepadAxisBuffer;
import static org.lwjgl.glfw.CallbackBridge.sGamepadButtonBuffer;
import android.view.KeyEvent;
import android.view.MotionEvent;
import fr.spse.gamepad_remapper.GamepadHandler;
public class DirectGamepad implements GamepadHandler {
@Override
public void handleGamepadInput(int keycode, float value) {
int gKeycode = -1, gAxis = -1;
switch (keycode) {
case KeyEvent.KEYCODE_BUTTON_A: gKeycode = GamepadKeycodes.GLFW_GAMEPAD_BUTTON_A; break;
case KeyEvent.KEYCODE_BUTTON_B: gKeycode = GamepadKeycodes.GLFW_GAMEPAD_BUTTON_B; break;
case KeyEvent.KEYCODE_BUTTON_X: gKeycode = GamepadKeycodes.GLFW_GAMEPAD_BUTTON_X; break;
case KeyEvent.KEYCODE_BUTTON_Y: gKeycode = GamepadKeycodes.GLFW_GAMEPAD_BUTTON_Y; break;
case KeyEvent.KEYCODE_BUTTON_L1: gKeycode = GamepadKeycodes.GLFW_GAMEPAD_BUTTON_LEFT_BUMPER; break;
case KeyEvent.KEYCODE_BUTTON_R1: gKeycode = GamepadKeycodes.GLFW_GAMEPAD_BUTTON_RIGHT_BUMPER; break;
case KeyEvent.KEYCODE_BUTTON_L2:
case MotionEvent.AXIS_LTRIGGER:
gAxis = GamepadKeycodes.GLFW_GAMEPAD_AXIS_LEFT_TRIGGER;
break;
case KeyEvent.KEYCODE_BUTTON_R2:
case MotionEvent.AXIS_RTRIGGER:
gAxis = GamepadKeycodes.GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER;
break;
case KeyEvent.KEYCODE_BUTTON_THUMBL: gKeycode = GamepadKeycodes.GLFW_GAMEPAD_BUTTON_LEFT_THUMB; break;
case KeyEvent.KEYCODE_BUTTON_THUMBR: gKeycode = GamepadKeycodes.GLFW_GAMEPAD_BUTTON_RIGHT_THUMB; break;
case KeyEvent.KEYCODE_BUTTON_START: gKeycode = GamepadKeycodes.GLFW_GAMEPAD_BUTTON_START; break;
case KeyEvent.KEYCODE_BUTTON_SELECT: gKeycode = GamepadKeycodes.GLFW_GAMEPAD_BUTTON_BACK; break;
case KeyEvent.KEYCODE_DPAD_UP: gKeycode = GamepadKeycodes.GLFW_GAMEPAD_BUTTON_DPAD_UP; break;
case KeyEvent.KEYCODE_DPAD_DOWN: gKeycode = GamepadKeycodes.GLFW_GAMEPAD_BUTTON_DPAD_DOWN; break;
case KeyEvent.KEYCODE_DPAD_LEFT: gKeycode = GamepadKeycodes.GLFW_GAMEPAD_BUTTON_DPAD_LEFT; break;
case KeyEvent.KEYCODE_DPAD_RIGHT: gKeycode = GamepadKeycodes.GLFW_GAMEPAD_BUTTON_DPAD_RIGHT; break;
case KeyEvent.KEYCODE_DPAD_CENTER:
// Behave the same way as the Gamepad here, as GLFW doesn't have a keycode
// for the dpad center.
sGamepadButtonBuffer.put(GamepadKeycodes.GLFW_GAMEPAD_BUTTON_DPAD_UP, GamepadKeycodes.GLFW_RELEASE);
sGamepadButtonBuffer.put(GamepadKeycodes.GLFW_GAMEPAD_BUTTON_DPAD_DOWN, GamepadKeycodes.GLFW_RELEASE);
sGamepadButtonBuffer.put(GamepadKeycodes.GLFW_GAMEPAD_BUTTON_DPAD_LEFT, GamepadKeycodes.GLFW_RELEASE);
sGamepadButtonBuffer.put(GamepadKeycodes.GLFW_GAMEPAD_BUTTON_DPAD_RIGHT, GamepadKeycodes.GLFW_RELEASE);
return;
case MotionEvent.AXIS_X: gAxis = GamepadKeycodes.GLFW_GAMEPAD_AXIS_LEFT_X; break;
case MotionEvent.AXIS_Y: gAxis = GamepadKeycodes.GLFW_GAMEPAD_AXIS_LEFT_Y; break;
case MotionEvent.AXIS_Z: gAxis = GamepadKeycodes.GLFW_GAMEPAD_AXIS_RIGHT_X; break;
case MotionEvent.AXIS_RZ: gAxis = GamepadKeycodes.GLFW_GAMEPAD_AXIS_RIGHT_Y; break;
case MotionEvent.AXIS_HAT_X:
sGamepadButtonBuffer.put(
GamepadKeycodes.GLFW_GAMEPAD_BUTTON_DPAD_LEFT,
value < -0.85 ? GamepadKeycodes.GLFW_PRESS : GamepadKeycodes.GLFW_RELEASE
);
sGamepadButtonBuffer.put(
GamepadKeycodes.GLFW_GAMEPAD_BUTTON_DPAD_RIGHT,
value > 0.85 ? GamepadKeycodes.GLFW_PRESS : GamepadKeycodes.GLFW_RELEASE
);
return;
case MotionEvent.AXIS_HAT_Y:
sGamepadButtonBuffer.put(
GamepadKeycodes.GLFW_GAMEPAD_BUTTON_DPAD_UP,
value < -0.85 ? GamepadKeycodes.GLFW_PRESS : GamepadKeycodes.GLFW_RELEASE
);
sGamepadButtonBuffer.put(
GamepadKeycodes.GLFW_GAMEPAD_BUTTON_DPAD_DOWN,
value > 0.85 ? GamepadKeycodes.GLFW_PRESS : GamepadKeycodes.GLFW_RELEASE
);
return;
}
if(gKeycode != -1) {
sGamepadButtonBuffer.put(gKeycode, value > 0.85 ? GamepadKeycodes.GLFW_PRESS : GamepadKeycodes.GLFW_RELEASE);
}
if(gAxis != -1) {
sGamepadAxisBuffer.put(gAxis, value);
}
}
}
@@ -0,0 +1,17 @@
package net.kdt.pojavlaunch.customcontrols.gamepad.direct;
/**
* Interface that is called once when the GLFW implementation requests to switch from
* the default gamepad implementation to the direct one. The implementor of this interface
* must take the necessary steps to disable the default gamepad implementation and replace
* it with an instance of DirectGamepad.
* This is useful for switching from default to direct input after the user has already
* interacted with the gamepad.
*/
public interface DirectGamepadEnableHandler {
/**
* Called once when GLFW requests switching the gamepad mode from default to direct.
*/
void onDirectGamepadEnabled();
}
@@ -0,0 +1,31 @@
package net.kdt.pojavlaunch.customcontrols.gamepad.direct;
public class GamepadKeycodes {
public static final byte GLFW_RELEASE = 0;
public static final byte GLFW_PRESS = 1;
public static final short GLFW_GAMEPAD_BUTTON_A = 0;
public static final short GLFW_GAMEPAD_BUTTON_B = 1;
public static final short GLFW_GAMEPAD_BUTTON_X = 2;
public static final short GLFW_GAMEPAD_BUTTON_Y = 3;
public static final short GLFW_GAMEPAD_BUTTON_LEFT_BUMPER = 4;
public static final short GLFW_GAMEPAD_BUTTON_RIGHT_BUMPER = 5;
public static final short GLFW_GAMEPAD_BUTTON_BACK = 6;
public static final short GLFW_GAMEPAD_BUTTON_START = 7;
// Home button, unused because Android takes the home button events
// for itself
public static final short GLFW_GAMEPAD_BUTTON_GUIDE = 8;
public static final short GLFW_GAMEPAD_BUTTON_LEFT_THUMB = 9;
public static final short GLFW_GAMEPAD_BUTTON_RIGHT_THUMB = 10;
public static final short GLFW_GAMEPAD_BUTTON_DPAD_UP = 11;
public static final short GLFW_GAMEPAD_BUTTON_DPAD_RIGHT = 12;
public static final short GLFW_GAMEPAD_BUTTON_DPAD_DOWN = 13;
public static final short GLFW_GAMEPAD_BUTTON_DPAD_LEFT = 14;
public static final short GLFW_GAMEPAD_AXIS_LEFT_X = 0;
public static final short GLFW_GAMEPAD_AXIS_LEFT_Y = 1;
public static final short GLFW_GAMEPAD_AXIS_RIGHT_X = 2;
public static final short GLFW_GAMEPAD_AXIS_RIGHT_Y = 3;
public static final short GLFW_GAMEPAD_AXIS_LEFT_TRIGGER = 4;
public static final short GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER = 5;
}
@@ -2,8 +2,6 @@ package net.kdt.pojavlaunch.prefs.screens;
import android.content.Context;
import android.content.SharedPreferences;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.os.Bundle;
import androidx.preference.PreferenceCategory;
@@ -39,8 +39,10 @@ import java.util.concurrent.atomic.AtomicReference;
public class MinecraftDownloader {
private static final double ONE_MEGABYTE = (1024d * 1024d);
public static final String MINECRAFT_RES = "https://resources.download.minecraft.net/";
private static final String MAVEN_CENTRAL_REPO1 = "https://repo1.maven.org/maven2/";
private AtomicReference<Exception> mDownloaderThreadException;
private ArrayList<DownloaderTask> mScheduledDownloadTasks;
private ArrayList<File> mDeclaredNatives;
private AtomicLong mProcessedFileCounter;
private AtomicLong mProcessedSizeCounter; // Total bytes of processed files (passed SHA1 or downloaded)
private AtomicLong mInternetUsageCounter; // How many bytes downloaded over Internet
@@ -88,6 +90,7 @@ public class MinecraftDownloader {
mTargetJarFile = createGameJarPath(versionName);
mScheduledDownloadTasks = new ArrayList<>();
mDeclaredNatives = new ArrayList<>();
mProcessedFileCounter = new AtomicLong(0);
mProcessedSizeCounter = new AtomicLong(0);
mInternetUsageCounter = new AtomicLong(0);
@@ -120,6 +123,7 @@ public class MinecraftDownloader {
throw thrownException;
} else {
ensureJarFileCopy();
extractNatives(versionName);
}
}catch (InterruptedException e) {
// Interrupted while waiting, which means that the download was cancelled.
@@ -167,6 +171,25 @@ public class MinecraftDownloader {
org.apache.commons.io.FileUtils.copyFile(mSourceJarFile, mTargetJarFile, false);
}
private void extractNatives(String versionName) throws IOException {
if(mDeclaredNatives.isEmpty()) return;
int totalCount = mDeclaredNatives.size();
ProgressLayout.setProgress(ProgressLayout.DOWNLOAD_MINECRAFT, 0,
R.string.newdl_extracting_native_libraries, 0, totalCount);
File targetDirectory = new File(Tools.DIR_CACHE, "natives/"+versionName);
FileUtils.ensureDirectory(targetDirectory);
NativesExtractor nativesExtractor = new NativesExtractor(targetDirectory);
int extractedCount = 0;
for(File source : mDeclaredNatives) {
nativesExtractor.extractFromAar(source);
extractedCount++;
ProgressLayout.setProgress(ProgressLayout.DOWNLOAD_MINECRAFT, extractedCount * 100 / totalCount,
R.string.newdl_extracting_native_libraries, extractedCount, totalCount);
}
}
private File downloadGameJson(JMinecraftVersionList.Version verInfo) throws IOException, MirrorTamperedException {
File targetFile = createGameJsonPath(verInfo.id);
if(verInfo.sha1 == null && targetFile.canRead() && targetFile.isFile())
@@ -256,7 +279,8 @@ public class MinecraftDownloader {
long size, boolean skipIfFailed) throws IOException {
FileUtils.ensureParentDirectory(targetFile);
mTotalFileCount++;
if(size < 0) {
// Only attempt to check size if we still use the size counter and didn't switch to file counter.
if(size <= 0 && !mUseFileCounter) {
size = DownloadMirror.getContentLengthMirrored(downloadClass, url);
}
if(size < 0) {
@@ -273,13 +297,31 @@ public class MinecraftDownloader {
);
}
/**
* Schedule the download of an AAR library containing the required natives, for later extraction
* and adding to the library path.
* @param baseRepository the source Maven repository to download from.
* @param dependentLibrary the DependentLibrary to get the path from
* @throws IOException in case if download scheduling fails.
*/
private void scheduleNativeLibraryDownload(String baseRepository, DependentLibrary dependentLibrary) throws IOException {
String path = FileUtils.removeExtension(Tools.artifactToPath(dependentLibrary)) + ".aar";
String downloadUrl = baseRepository + path;
File targetPath = new File(Tools.DIR_HOME_LIBRARY, path);
mDeclaredNatives.add(targetPath);
scheduleDownload(targetPath, DownloadMirror.DOWNLOAD_CLASS_LIBRARIES, downloadUrl, null, 0, true);
}
private void scheduleLibraryDownloads(DependentLibrary[] dependentLibraries) throws IOException {
Tools.preProcessLibraries(dependentLibraries);
growDownloadList(dependentLibraries.length);
for(DependentLibrary dependentLibrary : dependentLibraries) {
// Don't download lwjgl, we have our own bundled in.
if(dependentLibrary.name.startsWith("org.lwjgl")) continue;
// Special handling for JNA Android natives
if(dependentLibrary.name.startsWith("net.java.dev.jna:jna:")) {
scheduleNativeLibraryDownload(MAVEN_CENTRAL_REPO1, dependentLibrary);
}
String libArtifactPath = Tools.artifactToPath(dependentLibrary);
String sha1 = null, url = null;
long size = 0;
@@ -0,0 +1,116 @@
package net.kdt.pojavlaunch.tasks;
import net.kdt.pojavlaunch.Architecture;
import net.kdt.pojavlaunch.Tools;
import net.kdt.pojavlaunch.utils.FileUtils;
import java.io.File;
import java.io.FileInputStream;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.zip.CRC32;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
public class NativesExtractor {
private static final ArrayList<String> LIBRARY_BLACKLIST = createLibraryBlacklist();
private final File mDestinationDir;
private final String mLibraryLocation;
public NativesExtractor(File mDestinationDir) {
this.mDestinationDir = mDestinationDir;
this.mLibraryLocation = "jni/"+getAarArchitectureName()+"/";
}
/**
* Create a library blacklist so that downloaded natives are not able to
* override built-in libraries.
* @return the resulting blacklist of library file names
*/
private static ArrayList<String> createLibraryBlacklist() {
String[] includedLibraryNames = new File(Tools.NATIVE_LIB_DIR).list();
ArrayList<String> blacklist = new ArrayList<>(includedLibraryNames.length);
for(String libraryName : includedLibraryNames) {
// allow overriding jnidispatch (as the integrated version may be too old)
if(libraryName.equals("libjnidispatch.so")) continue;
blacklist.add(libraryName);
}
blacklist.trimToSize();
return blacklist;
}
private static String getAarArchitectureName() {
int architecture = Architecture.getDeviceArchitecture();
switch (architecture) {
case Architecture.ARCH_ARM:
return "armeabi-v7a";
case Architecture.ARCH_ARM64:
return "arm64-v8a";
case Architecture.ARCH_X86:
return "x86";
case Architecture.ARCH_X86_64:
return "x86_64";
}
throw new RuntimeException("Unknown CPU architecture: "+architecture);
}
public void extractFromAar(File source) throws IOException {
byte[] buffer = new byte[8192];
try (FileInputStream fileInputStream = new FileInputStream(source);
ZipInputStream zipInputStream = new ZipInputStream(fileInputStream)) {
// Wrap the ZIP input stream into a non-closeable stream to
// avoid it being closed by processEntry()
NonCloseableInputStream entryCopyStream = new NonCloseableInputStream(zipInputStream);
ZipEntry entry;
while((entry = zipInputStream.getNextEntry()) != null) {
String entryName = entry.getName();
if(!entryName.startsWith(mLibraryLocation) || entry.isDirectory()) continue;
// Entry name is actually the full path, so we need to strip the path before extraction
entryName = FileUtils.getFileName(entryName);
// getFileName may make the file name null, avoid that case.
if(entryName == null || LIBRARY_BLACKLIST.contains(entryName)) continue;
processEntry(entryCopyStream, entry, new File(mDestinationDir, entryName), buffer);
}
}
}
private static long fileCrc32(File target, byte[] buffer) throws IOException {
try(FileInputStream fileInputStream = new FileInputStream(target)) {
CRC32 crc32 = new CRC32();
int len;
while((len = fileInputStream.read(buffer)) != -1) {
crc32.update(buffer, 0, len);
}
return crc32.getValue();
}
}
private void processEntry(InputStream sourceStream, ZipEntry zipEntry, File entryDestination, byte[] buffer) throws IOException {
if(entryDestination.exists()) {
long expectedSize = zipEntry.getSize();
long expectedCrc32 = zipEntry.getCrc();
long realSize = entryDestination.length();
long realCrc32 = fileCrc32(entryDestination, buffer);
// File in archive is the same as the local one, don't extract
if(realSize == expectedSize && realCrc32 == expectedCrc32) return;
}
// copyInputStreamToFile copies the stream to a file and then closes it.
org.apache.commons.io.FileUtils.copyInputStreamToFile(sourceStream, entryDestination);
}
private static class NonCloseableInputStream extends FilterInputStream {
protected NonCloseableInputStream(InputStream in) {
super(in);
}
@Override
public void close() {
// Do nothing (the point of this class)
}
}
}
@@ -24,6 +24,17 @@ public class FileUtils {
return pathOrUrl.substring(lastSlashIndex);
}
/**
* Remove the extension (all text after the last dot) from a path/URL string.
* @param pathOrUrl the path or the URL of the file
* @return the input with the extension removed
*/
public static String removeExtension(String pathOrUrl) {
int lastDotIndex = pathOrUrl.lastIndexOf('.');
if(lastDotIndex == -1) return pathOrUrl;
return pathOrUrl.substring(0, lastDotIndex);
}
/**
* Ensure that a directory exists, is a directory and is writable.
* @param targetFile the directory to check
@@ -1,6 +1,8 @@
package org.lwjgl.glfw;
import net.kdt.pojavlaunch.*;
import net.kdt.pojavlaunch.customcontrols.gamepad.direct.DirectGamepadEnableHandler;
import android.content.*;
import android.util.Log;
import android.view.Choreographer;
@@ -8,6 +10,10 @@ import android.view.Choreographer;
import androidx.annotation.Keep;
import androidx.annotation.Nullable;
import java.lang.ref.WeakReference;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.util.ArrayList;
import dalvik.annotation.optimization.CriticalNative;
@@ -16,6 +22,8 @@ public class CallbackBridge {
public static final Choreographer sChoreographer = Choreographer.getInstance();
private static boolean isGrabbing = false;
private static final ArrayList<GrabListener> grabListeners = new ArrayList<>();
// Use a weak reference here to avoid possibly statically referencing a Context.
private static @Nullable WeakReference<DirectGamepadEnableHandler> sDirectGamepadEnableHandler;
public static final int CLIPBOARD_COPY = 2000;
public static final int CLIPBOARD_PASTE = 2001;
@@ -27,6 +35,10 @@ public class CallbackBridge {
public volatile static boolean holdingAlt, holdingCapslock, holdingCtrl,
holdingNumlock, holdingShift;
public static final ByteBuffer sGamepadButtonBuffer;
public static final FloatBuffer sGamepadAxisBuffer;
public static boolean sGamepadDirectInput = false;
public static void putMouseEventWithCoords(int button, float x, float y) {
putMouseEventWithCoords(button, true, x, y);
sChoreographer.postFrameCallbackDelayed(l -> putMouseEventWithCoords(button, false, x, y), 33);
@@ -165,6 +177,16 @@ public class CallbackBridge {
}
}
//Called from JRE side
@SuppressWarnings("unused")
@Keep
private static void onDirectInputEnable() {
Log.i("CallbackBridge", "onDirectInputEnable()");
DirectGamepadEnableHandler enableHandler = Tools.getWeakReference(sDirectGamepadEnableHandler);
if(enableHandler != null) enableHandler.onDirectGamepadEnabled();
sGamepadDirectInput = true;
}
//Called from JRE side
@SuppressWarnings("unused")
@Keep
@@ -194,6 +216,16 @@ public class CallbackBridge {
}
}
public static FloatBuffer createGamepadAxisBuffer() {
ByteBuffer axisByteBuffer = nativeCreateGamepadAxisBuffer();
// NOTE: hardcoded order (also in jre_lwjgl3glfw CallbackBridge)
return axisByteBuffer.order(ByteOrder.LITTLE_ENDIAN).asFloatBuffer();
}
public static void setDirectGamepadEnableHandler(DirectGamepadEnableHandler h) {
sDirectGamepadEnableHandler = new WeakReference<>(h);
}
@Keep @CriticalNative public static native void nativeSetUseInputStackQueue(boolean useInputStackQueue);
@Keep @CriticalNative private static native boolean nativeSendChar(char codepoint);
@@ -206,8 +238,12 @@ public class CallbackBridge {
@Keep @CriticalNative private static native void nativeSendScroll(double xoffset, double yoffset);
@Keep @CriticalNative private static native void nativeSendScreenSize(int width, int height);
public static native void nativeSetWindowAttrib(int attrib, int value);
private static native ByteBuffer nativeCreateGamepadButtonBuffer();
private static native ByteBuffer nativeCreateGamepadAxisBuffer();
static {
System.loadLibrary("pojavexec");
sGamepadButtonBuffer = nativeCreateGamepadButtonBuffer();
sGamepadAxisBuffer = createGamepadAxisBuffer();
}
}
@@ -28,6 +28,11 @@ typedef void GLFW_invoke_Key_func(void* window, int key, int scancode, int actio
typedef void GLFW_invoke_MouseButton_func(void* window, int button, int action, int mods);
typedef void GLFW_invoke_Scroll_func(void* window, double xoffset, double yoffset);
typedef struct {
unsigned char buttons [15];
float axes[6];
} GLFWgamepadstate;
struct pojav_environ_s {
struct ANativeWindow* pojavWindow;
basic_render_window_t* mainWindowBundle;
@@ -42,6 +47,7 @@ struct pojav_environ_s {
double cursorX, cursorY, cLastX, cLastY;
jmethodID method_accessAndroidClipboard;
jmethodID method_onGrabStateChanged;
jmethodID method_onDirectInputEnable;
jmethodID method_glftSetWindowAttrib;
jmethodID method_internalWindowSizeChanged;
jmethodID method_internalChangeMonitorSize;
@@ -57,6 +63,7 @@ struct pojav_environ_s {
bool isInputReady, isCursorEntered, isUseStackQueueCall, shouldUpdateMouse;
bool shouldUpdateMonitorSize, monitorSizeConsumed;
int savedWidth, savedHeight;
GLFWgamepadstate gamepadState;
#define ADD_CALLBACK_WWIN(NAME) \
GLFW_invoke_##NAME##_func* GLFW_invoke_##NAME;
ADD_CALLBACK_WWIN(Char);
@@ -32,6 +32,15 @@
#define EVENT_TYPE_MOUSE_BUTTON 1006
#define EVENT_TYPE_SCROLL 1007
#define TRY_ATTACH_ENV(env_name, vm, error_message, then) JNIEnv* env_name;\
do { \
env_name = get_attached_env(vm); \
if(env_name == NULL) { \
printf(error_message); \
then \
} \
} while(0)
static void registerFunctions(JNIEnv *env);
jint JNI_OnLoad(JavaVM* vm, __attribute__((unused)) void* reserved) {
@@ -44,6 +53,7 @@ jint JNI_OnLoad(JavaVM* vm, __attribute__((unused)) void* reserved) {
pojav_environ->bridgeClazz = (*dvEnv)->NewGlobalRef(dvEnv,(*dvEnv) ->FindClass(dvEnv,"org/lwjgl/glfw/CallbackBridge"));
pojav_environ->method_accessAndroidClipboard = (*dvEnv)->GetStaticMethodID(dvEnv, pojav_environ->bridgeClazz, "accessAndroidClipboard", "(ILjava/lang/String;)Ljava/lang/String;");
pojav_environ->method_onGrabStateChanged = (*dvEnv)->GetStaticMethodID(dvEnv, pojav_environ->bridgeClazz, "onGrabStateChanged", "(Z)V");
pojav_environ->method_onDirectInputEnable = (*dvEnv)->GetStaticMethodID(dvEnv, pojav_environ->bridgeClazz, "onDirectInputEnable", "()V");
pojav_environ->isUseStackQueueCall = JNI_FALSE;
} else if (pojav_environ->dalvikJavaVMPtr != vm) {
LOGI("Saving JVM environ...");
@@ -249,7 +259,7 @@ JNIEXPORT jstring JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeClipboard(JNI
(*pojav_environ->dalvikJavaVMPtr)->AttachCurrentThread(pojav_environ->dalvikJavaVMPtr, &dalvikEnv, NULL);
assert(dalvikEnv != NULL);
assert(pojav_environ->bridgeClazz != NULL);
LOGD("Clipboard: Converting string\n");
char *copySrcC;
jstring copyDst = NULL;
@@ -262,7 +272,7 @@ JNIEXPORT jstring JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeClipboard(JNI
jstring pasteDst = convertStringJVM(dalvikEnv, env, (jstring) (*dalvikEnv)->CallStaticObjectMethod(dalvikEnv, pojav_environ->bridgeClazz, pojav_environ->method_accessAndroidClipboard, action, copyDst));
if (copySrc) {
(*dalvikEnv)->DeleteLocalRef(dalvikEnv, copyDst);
(*dalvikEnv)->DeleteLocalRef(dalvikEnv, copyDst);
(*env)->ReleaseByteArrayElements(env, copySrc, (jbyte *)copySrcC, 0);
}
(*pojav_environ->dalvikJavaVMPtr)->DetachCurrentThread(pojav_environ->dalvikJavaVMPtr);
@@ -283,13 +293,18 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSetInputRead
}
JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSetGrabbing(__attribute__((unused)) JNIEnv* env, __attribute__((unused)) jclass clazz, jboolean grabbing) {
JNIEnv *dalvikEnv;
(*pojav_environ->dalvikJavaVMPtr)->AttachCurrentThread(pojav_environ->dalvikJavaVMPtr, &dalvikEnv, NULL);
(*dalvikEnv)->CallStaticVoidMethod(dalvikEnv, pojav_environ->bridgeClazz, pojav_environ->method_onGrabStateChanged, grabbing);
(*pojav_environ->dalvikJavaVMPtr)->DetachCurrentThread(pojav_environ->dalvikJavaVMPtr);
TRY_ATTACH_ENV(dvm_env, pojav_environ->dalvikJavaVMPtr, "nativeSetGrabbing failed!\n", return;);
(*dvm_env)->CallStaticVoidMethod(dvm_env, pojav_environ->bridgeClazz, pojav_environ->method_onGrabStateChanged, grabbing);
pojav_environ->isGrabbing = grabbing;
}
JNIEXPORT jboolean JNICALL
Java_org_lwjgl_glfw_CallbackBridge_nativeEnableGamepadDirectInput(__attribute__((unused)) JNIEnv *env, __attribute__((unused)) jclass clazz) {
TRY_ATTACH_ENV(dvm_env, pojav_environ->dalvikJavaVMPtr, "nativeEnableGamepadDirectInput failed!\n", return JNI_FALSE;);
(*dvm_env)->CallStaticVoidMethod(dvm_env, pojav_environ->bridgeClazz, pojav_environ->method_onDirectInputEnable);
return JNI_TRUE;
}
jboolean critical_send_char(jchar codepoint) {
if (pojav_environ->GLFW_invoke_Char && pojav_environ->isInputReady) {
if (pojav_environ->isUseStackQueueCall) {
@@ -449,7 +464,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSetWindowAttrib(
// in environ for the Android UI thread but this is the only place that uses it
// (very rarely, only in lifecycle callbacks) so i dont care
JNIEnv *jvm_env = get_attached_env(pojav_environ->runtimeJavaVMPtr);
TRY_ATTACH_ENV(jvm_env, pojav_environ->runtimeJavaVMPtr, "nativeSetWindowAttrib failed: %i", return;);
(*jvm_env)->CallStaticVoidMethod(
jvm_env, pojav_environ->vmGlfwClass,
@@ -524,3 +539,18 @@ static void registerFunctions(JNIEnv *env) {
use_critical_cc ? critical_fcns : noncritical_fcns,
sizeof(critical_fcns)/sizeof(critical_fcns[0]));
}
JNIEXPORT jlong JNICALL
Java_org_lwjgl_glfw_GLFW_internalGetGamepadDataPointer(JNIEnv *env, jclass clazz) {
return (jlong) &pojav_environ->gamepadState;
}
JNIEXPORT jobject JNICALL
Java_org_lwjgl_glfw_CallbackBridge_nativeCreateGamepadButtonBuffer(JNIEnv *env, jclass clazz) {
return (*env)->NewDirectByteBuffer(env, &pojav_environ->gamepadState.buttons, sizeof(pojav_environ->gamepadState.buttons));
}
JNIEXPORT jobject JNICALL
Java_org_lwjgl_glfw_CallbackBridge_nativeCreateGamepadAxisBuffer(JNIEnv *env, jclass clazz) {
return (*env)->NewDirectByteBuffer(env, &pojav_environ->gamepadState.axes, sizeof(pojav_environ->gamepadState.axes));
}
+1 -1
View File
@@ -164,7 +164,7 @@ JNIEnv* get_attached_env(JavaVM* jvm) {
env_result = (*jvm)->AttachCurrentThread(jvm, &jvm_env, NULL);
}
if(env_result != JNI_OK) {
printf("get_attached_env failed: %i", env_result);
printf("get_attached_env failed: %i\n", env_result);
return NULL;
}
return jvm_env;
@@ -429,4 +429,5 @@
<string name="bta_installer_available_versions">Supported BTA versions</string>
<string name="bta_installer_untested_versions">Untested BTA versions</string>
<string name="bta_installer_nightly_versions">Nightly BTA versions</string>
<string name="newdl_extracting_native_libraries">Extracting native libraries (%d/%d)</string>
</resources>
Binary file not shown.
@@ -1,4 +1,5 @@
package org.lwjgl.glfw;
import java.nio.ByteBuffer;
import java.util.*;
public class CallbackBridge {
@@ -18,6 +19,8 @@ public class CallbackBridge {
public static final int ANDROID_TYPE_GRAB_STATE = 0;
public static final boolean INPUT_DEBUG_ENABLED;
public static boolean sGamepadDirectEnabled;
// TODO send grab state event to Android
@@ -40,6 +43,11 @@ public class CallbackBridge {
}
public static void enableGamepadDirectInput() {
if(sGamepadDirectEnabled) return;
sGamepadDirectEnabled = nativeEnableGamepadDirectInput();
}
public static void sendData(int type, String data) {
nativeSendData(false, type, data);
}
@@ -47,5 +55,8 @@ public class CallbackBridge {
public static native boolean nativeSetInputReady(boolean ready);
public static native String nativeClipboard(int action, byte[] copy);
public static native void nativeSetGrabbing(boolean grab);
public static native ByteBuffer nativeCreateGamepadButtonBuffer();
public static native ByteBuffer nativeCreateGamepadAxisBuffer();
private static native boolean nativeEnableGamepadDirectInput();
}
@@ -13,6 +13,7 @@ import javax.annotation.*;
import org.lwjgl.*;
import org.lwjgl.system.*;
import org.lwjgl.system.MemoryUtil;
import static org.lwjgl.opengl.GL20.*;
import static org.lwjgl.system.APIUtil.*;
@@ -24,8 +25,9 @@ import java.util.*;
public class GLFW
{
static FloatBuffer joystickData = (FloatBuffer)FloatBuffer.allocate(8).flip();
static ByteBuffer buttonData = (ByteBuffer)ByteBuffer.allocate(8).flip();
static FloatBuffer joystickAxisData;
static ByteBuffer joystickButtonData;
static ByteBuffer empty = (ByteBuffer)ByteBuffer.allocate(0);
/** The major version number of the GLFW library. This is incremented when the API is changed in non-compatible ways. */
public static final int GLFW_VERSION_MAJOR = 3;
@@ -515,6 +517,7 @@ public class GLFW
private static final String PROP_WINDOW_WIDTH = "glfwstub.windowWidth";
private static final String PROP_WINDOW_HEIGHT= "glfwstub.windowHeight";
public static long mainContext = 0;
private static long gamepadDataPointer;
static {
try {
@@ -636,6 +639,8 @@ public class GLFW
return win;
}
private static native long internalGetGamepadDataPointer();
// Generated stub callback methods
public static GLFWCharCallback glfwSetCharCallback(@NativeType("GLFWwindow *") long window, @Nullable @NativeType("GLFWcharfun") GLFWCharCallbackI cbfun) {
GLFWCharCallback lastCallback = mGLFWCharCallback;
@@ -805,6 +810,10 @@ public class GLFW
mGLFWInitialTime = (double) System.nanoTime();
long __functionAddress = Functions.Init;
isGLFWReady = invokeI(__functionAddress) != 0;
gamepadDataPointer = internalGetGamepadDataPointer();
// NOTE: hardcoded order (also in android CallbackBridge)
joystickAxisData = CallbackBridge.nativeCreateGamepadAxisBuffer().order(ByteOrder.LITTLE_ENDIAN).asFloatBuffer();
joystickButtonData = CallbackBridge.nativeCreateGamepadButtonBuffer();
}
return isGLFWReady;
}
@@ -1207,50 +1216,60 @@ public class GLFW
}
public static boolean glfwJoystickPresent(int jid) {
if(jid == 0) {
if(jid == GLFW_JOYSTICK_1) {
CallbackBridge.enableGamepadDirectInput();
return true;
}else return false;
}
public static String glfwGetJoystickName(int jid) {
if(jid == 0) {
return "AIC event bus controller";
if(jid == GLFW_JOYSTICK_1) {
return "Pojav XBOX 360 compatible gamepad";
}else return null;
}
public static FloatBuffer glfwGetJoystickAxes(int jid) {
if(jid == 0) {
return joystickData;
if(jid == GLFW_JOYSTICK_1) {
return joystickAxisData;
}else return null;
}
public static ByteBuffer glfwGetJoystickButtons(int jid) {
if(jid == 0) {
return buttonData;
if(jid == GLFW_JOYSTICK_1) {
return joystickButtonData;
}else return null;
}
public static ByteBuffer glfwGetjoystickHats(int jid) {
return null;
public static ByteBuffer glfwGetJoystickHats(int jid) {
if(jid == GLFW_JOYSTICK_1) {
return empty; // Maybe implement this later?
}else return null;
}
public static boolean glfwJoystickIsGamepad(int jid) {
if(jid == 0) return true;
if(jid == GLFW_JOYSTICK_1) return true;
else return false;
}
public static String glfwGetJoystickGUID(int jid) {
if(jid == 0) return "aio0";
// Return Xbox 360 controller GUID
if(jid == GLFW_JOYSTICK_1) return "030000005e0400008e02000056210000";
else return null;
}
private static long mUserPointer;
public static long glfwGetJoystickUserPointer(int jid) {
return 0;
return mUserPointer;
}
public static void glfwSetJoystickUserPointer(int jid, long pointer) {
mUserPointer = pointer;
}
public static boolean glfwUpdateGamepadMappings(ByteBuffer string) {
return false;
}
public static String glfwGetGamepadName(int jid) {
return null;
if(jid == GLFW_JOYSTICK_1) return "Pojav XBOX 360 compatible gamepad";
else return null;
}
public static boolean glfwGetGamepadState(int jid, GLFWGamepadState state) {
return false;
if(jid != 0) return false;
MemoryUtil.memCopy(gamepadDataPointer, state.address(), state.sizeof());
return true;
}
/** Array version of: {@link #glfwGetVersion GetVersion} */
@@ -1306,17 +1325,26 @@ public class GLFW
*/
/** Array version of: {@link #glfwGetMonitorContentScale GetMonitorContentScale} */
/*
public static void glfwGetMonitorContentScale(@NativeType("GLFWmonitor *") long monitor, @Nullable @NativeType("float *") float[] xscale, @Nullable @NativeType("float *") float[] yscale) {
long __functionAddress = Functions.GetMonitorContentScale;
if (CHECKS) {
// check(monitor);
checkSafe(xscale, 1);
checkSafe(yscale, 1);
}
invokePPPV(monitor, xscale, yscale, __functionAddress);
xscale[0] = 1;
yscale[0] = 1;
}
public static void glfwGetMonitorContentScale(@NativeType("GLFWmonitor *") long monitor, @NativeType("float *") @Nullable FloatBuffer xscale, @NativeType("float *") @Nullable FloatBuffer yscale) {
if (CHECKS) {
// check(monitor);
checkSafe(xscale, 1);
checkSafe(yscale, 1);
}
xscale.put(0, 1);
yscale.put(0, 1);
}
*/
/** Array version of: {@link #glfwGetWindowPos GetWindowPos} */
public static void glfwGetWindowPos(@NativeType("GLFWwindow *") long window, @Nullable @NativeType("int *") int[] xpos, @Nullable @NativeType("int *") int[] ypos) {
@@ -1376,7 +1404,7 @@ public class GLFW
}
invokePPPV(window, xscale, yscale, __functionAddress);
}
*/
/** Array version of: {@link #glfwGetCursorPos GetCursorPos} */
public static void glfwGetCursorPos(@NativeType("GLFWwindow *") long window, @Nullable @NativeType("double *") double[] xpos, @Nullable @NativeType("double *") double[] ypos) {