Compare commits
14
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
81c6813a6b | ||
|
|
d713fe52ea | ||
|
|
92bde837fd | ||
|
|
1e060d1aa8 | ||
|
|
fab0186cbe | ||
|
|
988d3bbcb6 | ||
|
|
9e53552a8c | ||
|
|
740568fafa | ||
|
|
4903cfc8d3 | ||
|
|
21cfcdb15e | ||
|
|
ffc74c502a | ||
|
|
4e1bdd8675 | ||
|
|
0ee0dfecc2 | ||
|
|
5a98a43d21 |
No files matched your search
Binary file not shown.
@@ -1 +1 @@
|
||||
1687691695196
|
||||
1738839797928
|
||||
Binary file not shown.
@@ -1 +1 @@
|
||||
1692525087345
|
||||
1738839797913
|
||||
Binary file not shown.
@@ -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,9 +325,17 @@ 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(getLWJGL3ClassPath() + ":" + launchClassPath);
|
||||
javaArgList.add(launchClassPath + ":" + getLWJGL3ClassPath());
|
||||
|
||||
javaArgList.add(versionInfo.mainClass);
|
||||
javaArgList.addAll(Arrays.asList(launchArgs));
|
||||
|
||||
+5
@@ -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);
|
||||
}
|
||||
}
|
||||
+14
-2
@@ -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);
|
||||
}
|
||||
}
|
||||
+1
@@ -7,4 +7,5 @@ public interface GamepadDataProvider {
|
||||
GamepadMap getGameMap();
|
||||
boolean isGrabbing();
|
||||
void attachGrabListener(GrabListener grabListener);
|
||||
void detachGrabListener(GrabListener grabListener);
|
||||
}
|
||||
+5
@@ -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);
|
||||
|
||||
+78
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
+17
@@ -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();
|
||||
}
|
||||
+31
@@ -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;
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package net.kdt.pojavlaunch.fragments;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.widget.ExpandableListAdapter;
|
||||
|
||||
import net.kdt.pojavlaunch.R;
|
||||
import net.kdt.pojavlaunch.modloaders.BTADownloadTask;
|
||||
import net.kdt.pojavlaunch.modloaders.BTAUtils;
|
||||
import net.kdt.pojavlaunch.modloaders.BTAVersionListAdapter;
|
||||
import net.kdt.pojavlaunch.modloaders.ModloaderListenerProxy;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class BTAInstallFragment extends ModVersionListFragment<BTAUtils.BTAVersionList> {
|
||||
public static final String TAG = "BTAInstallFragment";
|
||||
|
||||
public BTAInstallFragment() {
|
||||
super(TAG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTitleText() {
|
||||
return R.string.select_bta_version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNoDataMsg() {
|
||||
return R.string.modloader_dl_failed_to_load_list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BTAUtils.BTAVersionList loadVersionList() throws IOException {
|
||||
return BTAUtils.downloadVersionList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpandableListAdapter createAdapter(BTAUtils.BTAVersionList versionList, LayoutInflater layoutInflater) {
|
||||
return new BTAVersionListAdapter(versionList, layoutInflater);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Runnable createDownloadTask(Object selectedVersion, ModloaderListenerProxy listenerProxy) {
|
||||
return new BTADownloadTask(listenerProxy, (BTAUtils.BTAVersion) selectedVersion);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDownloadFinished(Context context, File downloadedFile) {
|
||||
// We don't have to do anything after the BTADownloadTask ends, so this is a stub
|
||||
}
|
||||
}
|
||||
+1
-12
@@ -6,19 +6,8 @@ import net.kdt.pojavlaunch.modloaders.ModloaderListenerProxy;
|
||||
public class FabricInstallFragment extends FabriclikeInstallFragment {
|
||||
|
||||
public static final String TAG = "FabricInstallFragment";
|
||||
private static ModloaderListenerProxy sTaskProxy;
|
||||
|
||||
public FabricInstallFragment() {
|
||||
super(FabriclikeUtils.FABRIC_UTILS);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ModloaderListenerProxy getListenerProxy() {
|
||||
return sTaskProxy;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setListenerProxy(ModloaderListenerProxy listenerProxy) {
|
||||
sTaskProxy = listenerProxy;
|
||||
super(FabriclikeUtils.FABRIC_UTILS, TAG);
|
||||
}
|
||||
}
|
||||
+10
-3
@@ -21,6 +21,7 @@ import androidx.fragment.app.Fragment;
|
||||
import net.kdt.pojavlaunch.PojavApplication;
|
||||
import net.kdt.pojavlaunch.R;
|
||||
import net.kdt.pojavlaunch.Tools;
|
||||
import net.kdt.pojavlaunch.extra.ExtraCore;
|
||||
import net.kdt.pojavlaunch.modloaders.FabriclikeDownloadTask;
|
||||
import net.kdt.pojavlaunch.modloaders.FabriclikeUtils;
|
||||
import net.kdt.pojavlaunch.modloaders.FabricVersion;
|
||||
@@ -36,6 +37,7 @@ import java.util.concurrent.Future;
|
||||
|
||||
public abstract class FabriclikeInstallFragment extends Fragment implements ModloaderDownloadListener, CompoundButton.OnCheckedChangeListener {
|
||||
private final FabriclikeUtils mFabriclikeUtils;
|
||||
private final String mExtraTag;
|
||||
private Spinner mGameVersionSpinner;
|
||||
private FabricVersion[] mGameVersionArray;
|
||||
private Future<?> mGameVersionFuture;
|
||||
@@ -48,9 +50,10 @@ public abstract class FabriclikeInstallFragment extends Fragment implements Modl
|
||||
private Button mStartButton;
|
||||
private View mRetryView;
|
||||
private CheckBox mOnlyStableCheckbox;
|
||||
protected FabriclikeInstallFragment(FabriclikeUtils mFabriclikeUtils) {
|
||||
protected FabriclikeInstallFragment(FabriclikeUtils mFabriclikeUtils, String mFragmentTag) {
|
||||
super(R.layout.fragment_fabric_install);
|
||||
this.mFabriclikeUtils = mFabriclikeUtils;
|
||||
this.mExtraTag = mFragmentTag + "_proxy";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -290,6 +293,10 @@ public abstract class FabriclikeInstallFragment extends Fragment implements Modl
|
||||
mGameVersionSpinner.setAdapter(createAdapter(mGameVersionArray, mOnlyStableCheckbox.isChecked()));
|
||||
}
|
||||
|
||||
protected abstract ModloaderListenerProxy getListenerProxy();
|
||||
protected abstract void setListenerProxy(ModloaderListenerProxy listenerProxy);
|
||||
private ModloaderListenerProxy getListenerProxy() {
|
||||
return (ModloaderListenerProxy) ExtraCore.getValue(mExtraTag);
|
||||
}
|
||||
private void setListenerProxy(ModloaderListenerProxy listenerProxy) {
|
||||
ExtraCore.setValue(mExtraTag, listenerProxy);
|
||||
}
|
||||
}
|
||||
+3
-10
@@ -21,7 +21,9 @@ import java.util.List;
|
||||
|
||||
public class ForgeInstallFragment extends ModVersionListFragment<List<String>> {
|
||||
public static final String TAG = "ForgeInstallFragment";
|
||||
private static ModloaderListenerProxy sTaskProxy;
|
||||
public ForgeInstallFragment() {
|
||||
super(TAG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(@NonNull Context context) {
|
||||
@@ -38,15 +40,6 @@ public class ForgeInstallFragment extends ModVersionListFragment<List<String>> {
|
||||
return R.string.forge_dl_no_installer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModloaderListenerProxy getTaskProxy() {
|
||||
return sTaskProxy;
|
||||
}
|
||||
@Override
|
||||
public void setTaskProxy(ModloaderListenerProxy proxy) {
|
||||
sTaskProxy = proxy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> loadVersionList() throws IOException {
|
||||
return ForgeUtils.downloadForgeVersions();
|
||||
|
||||
+14
-4
@@ -16,6 +16,7 @@ import androidx.fragment.app.Fragment;
|
||||
|
||||
import net.kdt.pojavlaunch.R;
|
||||
import net.kdt.pojavlaunch.Tools;
|
||||
import net.kdt.pojavlaunch.extra.ExtraCore;
|
||||
import net.kdt.pojavlaunch.mirrors.DownloadMirror;
|
||||
import net.kdt.pojavlaunch.modloaders.ModloaderDownloadListener;
|
||||
import net.kdt.pojavlaunch.modloaders.ModloaderListenerProxy;
|
||||
@@ -25,14 +26,15 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public abstract class ModVersionListFragment<T> extends Fragment implements Runnable, View.OnClickListener, ExpandableListView.OnChildClickListener, ModloaderDownloadListener {
|
||||
public static final String TAG = "ForgeInstallFragment";
|
||||
private final String mExtraTag;
|
||||
private ExpandableListView mExpandableListView;
|
||||
private ProgressBar mProgressBar;
|
||||
private LayoutInflater mInflater;
|
||||
private View mRetryView;
|
||||
|
||||
public ModVersionListFragment() {
|
||||
public ModVersionListFragment(String mFragmentTag) {
|
||||
super(R.layout.fragment_mod_version_list);
|
||||
this.mExtraTag = mFragmentTag + "_proxy";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -148,11 +150,19 @@ public abstract class ModVersionListFragment<T> extends Fragment implements Runn
|
||||
});
|
||||
}
|
||||
|
||||
private void setTaskProxy(ModloaderListenerProxy proxy) {
|
||||
ExtraCore.setValue(mExtraTag, proxy);
|
||||
}
|
||||
|
||||
private ModloaderListenerProxy getTaskProxy() {
|
||||
return (ModloaderListenerProxy) ExtraCore.getValue(mExtraTag);
|
||||
}
|
||||
|
||||
public abstract int getTitleText();
|
||||
public abstract int getNoDataMsg();
|
||||
public abstract ModloaderListenerProxy getTaskProxy();
|
||||
|
||||
public abstract T loadVersionList() throws IOException;
|
||||
public abstract void setTaskProxy(ModloaderListenerProxy proxy);
|
||||
|
||||
public abstract ExpandableListAdapter createAdapter(T versionList, LayoutInflater layoutInflater);
|
||||
public abstract Runnable createDownloadTask(Object selectedVersion, ModloaderListenerProxy listenerProxy);
|
||||
public abstract void onDownloadFinished(Context context, File downloadedFile);
|
||||
|
||||
+3
-13
@@ -7,7 +7,6 @@ import android.widget.ExpandableListAdapter;
|
||||
|
||||
import net.kdt.pojavlaunch.JavaGUILauncherActivity;
|
||||
import net.kdt.pojavlaunch.R;
|
||||
import net.kdt.pojavlaunch.Tools;
|
||||
import net.kdt.pojavlaunch.modloaders.ModloaderListenerProxy;
|
||||
import net.kdt.pojavlaunch.modloaders.OptiFineDownloadTask;
|
||||
import net.kdt.pojavlaunch.modloaders.OptiFineUtils;
|
||||
@@ -18,7 +17,9 @@ import java.io.IOException;
|
||||
|
||||
public class OptiFineInstallFragment extends ModVersionListFragment<OptiFineUtils.OptiFineVersions> {
|
||||
public static final String TAG = "OptiFineInstallFragment";
|
||||
private static ModloaderListenerProxy sTaskProxy;
|
||||
public OptiFineInstallFragment() {
|
||||
super(TAG);
|
||||
}
|
||||
@Override
|
||||
public int getTitleText() {
|
||||
return R.string.of_dl_select_version;
|
||||
@@ -28,22 +29,11 @@ public class OptiFineInstallFragment extends ModVersionListFragment<OptiFineUtil
|
||||
public int getNoDataMsg() {
|
||||
return R.string.of_dl_failed_to_scrape;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModloaderListenerProxy getTaskProxy() {
|
||||
return sTaskProxy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OptiFineUtils.OptiFineVersions loadVersionList() throws IOException {
|
||||
return OptiFineUtils.downloadOptiFineVersions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTaskProxy(ModloaderListenerProxy proxy) {
|
||||
sTaskProxy = proxy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpandableListAdapter createAdapter(OptiFineUtils.OptiFineVersions versionList, LayoutInflater layoutInflater) {
|
||||
return new OptiFineVersionListAdapter(versionList, layoutInflater);
|
||||
|
||||
+2
@@ -35,5 +35,7 @@ public class ProfileTypeSelectFragment extends Fragment {
|
||||
Tools.swapFragment(requireActivity(), SearchModFragment.class, SearchModFragment.TAG, null));
|
||||
view.findViewById(R.id.modded_profile_quilt).setOnClickListener((v)->
|
||||
Tools.swapFragment(requireActivity(), QuiltInstallFragment.class, QuiltInstallFragment.TAG, null));
|
||||
view.findViewById(R.id.modded_profile_bta).setOnClickListener((v)->
|
||||
Tools.swapFragment(requireActivity(), BTAInstallFragment.class, BTAInstallFragment.TAG, null));
|
||||
}
|
||||
}
|
||||
+1
-11
@@ -9,16 +9,6 @@ public class QuiltInstallFragment extends FabriclikeInstallFragment {
|
||||
private static ModloaderListenerProxy sTaskProxy;
|
||||
|
||||
public QuiltInstallFragment() {
|
||||
super(FabriclikeUtils.QUILT_UTILS);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ModloaderListenerProxy getListenerProxy() {
|
||||
return sTaskProxy;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setListenerProxy(ModloaderListenerProxy listenerProxy) {
|
||||
sTaskProxy = listenerProxy;
|
||||
super(FabriclikeUtils.QUILT_UTILS, TAG);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package net.kdt.pojavlaunch.modloaders;
|
||||
|
||||
import android.util.Base64;
|
||||
import android.util.Base64OutputStream;
|
||||
import android.util.Log;
|
||||
|
||||
import com.kdt.mcgui.ProgressLayout;
|
||||
|
||||
import net.kdt.pojavlaunch.R;
|
||||
import net.kdt.pojavlaunch.Tools;
|
||||
import net.kdt.pojavlaunch.progresskeeper.ProgressKeeper;
|
||||
import net.kdt.pojavlaunch.utils.DownloadUtils;
|
||||
import net.kdt.pojavlaunch.utils.FileUtils;
|
||||
import net.kdt.pojavlaunch.value.launcherprofiles.LauncherProfiles;
|
||||
import net.kdt.pojavlaunch.value.launcherprofiles.MinecraftProfile;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class BTADownloadTask implements Runnable {
|
||||
private static final String BASE_JSON = "{\"inheritsFrom\":\"b1.7.3\",\"mainClass\":\"net.minecraft.client.Minecraft\",\"libraries\":[{\"name\":\"bta-client:bta-client:%1$s\",\"downloads\":{\"artifact\":{\"path\":\"bta-client/bta-client-%1$s.jar\",\"url\":\"%2$s\"}}}],\"id\":\"%3$s\"}";
|
||||
private final ModloaderDownloadListener mListener;
|
||||
private final BTAUtils.BTAVersion mBtaVersion;
|
||||
|
||||
public BTADownloadTask(ModloaderDownloadListener mListener, BTAUtils.BTAVersion mBtaVersion) {
|
||||
this.mListener = mListener;
|
||||
this.mBtaVersion = mBtaVersion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
ProgressKeeper.submitProgress(ProgressLayout.INSTALL_MODPACK, 0, R.string.fabric_dl_progress, "BTA");
|
||||
try {
|
||||
runCatching() ;
|
||||
mListener.onDownloadFinished(null);
|
||||
}catch (IOException e) {
|
||||
mListener.onDownloadError(e);
|
||||
}
|
||||
ProgressLayout.clearProgress(ProgressLayout.INSTALL_MODPACK);
|
||||
}
|
||||
|
||||
private String tryDownloadIcon() {
|
||||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
||||
try (Base64OutputStream base64OutputStream = new Base64OutputStream(byteArrayOutputStream, Base64.DEFAULT)){
|
||||
// Instead of appending and wasting memory with a StringBuilder, just write the prefix
|
||||
// to the stream before the base64 icon data.
|
||||
byteArrayOutputStream.write("data:image/png;base64,".getBytes(StandardCharsets.US_ASCII));
|
||||
DownloadUtils.download(mBtaVersion.iconUrl, base64OutputStream);
|
||||
return new String(byteArrayOutputStream.toByteArray(), StandardCharsets.US_ASCII);
|
||||
}catch (IOException e) {
|
||||
Log.w("BTADownloadTask", "Failed to download base64 icon", e);
|
||||
}finally {
|
||||
try {
|
||||
byteArrayOutputStream.close();
|
||||
} catch (IOException e) {
|
||||
Log.wtf("BTADownloadTask", "Failed to close a byte array stream??", e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void createJson(String btaVersionId) throws IOException {
|
||||
String btaJson = String.format(BASE_JSON, mBtaVersion.versionName, mBtaVersion.downloadUrl, btaVersionId);
|
||||
File jsonDir = new File(Tools.DIR_HOME_VERSION, btaVersionId);
|
||||
File jsonFile = new File(jsonDir, btaVersionId+".json");
|
||||
FileUtils.ensureDirectory(jsonDir);
|
||||
Tools.write(jsonFile.getAbsolutePath(), btaJson);
|
||||
}
|
||||
|
||||
// BTA doesn't have SHA1 checksums in its repositories, so the user may try to reinstall it
|
||||
// if it didn't work due to a broken download. So, for reinstalls like that to work,
|
||||
// we need to delete the old client jar to force the download of a new one.
|
||||
private void removeOldClient() throws IOException{
|
||||
File btaClientPath = new File(Tools.DIR_HOME_LIBRARY, String.format("bta-client/bta-client-%1$s.jar", mBtaVersion.versionName));
|
||||
if(btaClientPath.exists() && !btaClientPath.delete())
|
||||
throw new IOException("Failed to delete old client jar");
|
||||
}
|
||||
|
||||
private void createProfile(String btaVersionId) throws IOException {
|
||||
LauncherProfiles.load();
|
||||
MinecraftProfile btaProfile = new MinecraftProfile();
|
||||
btaProfile.lastVersionId = btaVersionId;
|
||||
btaProfile.name = "Better than Adventure!";
|
||||
// Allows for smooth upgrades
|
||||
btaProfile.gameDir = "./custom_instances/better_than_adventure";
|
||||
btaProfile.icon = tryDownloadIcon();
|
||||
LauncherProfiles.insertMinecraftProfile(btaProfile);
|
||||
LauncherProfiles.write();
|
||||
}
|
||||
|
||||
public void runCatching() throws IOException {
|
||||
removeOldClient();
|
||||
String btaVersionId = "bta-"+mBtaVersion.versionName;
|
||||
createJson(btaVersionId);
|
||||
createProfile(btaVersionId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
package net.kdt.pojavlaunch.modloaders;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.Keep;
|
||||
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import net.kdt.pojavlaunch.Tools;
|
||||
import net.kdt.pojavlaunch.utils.DownloadUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class BTAUtils {
|
||||
private static final String BASE_DOWNLOADS_URL = "https://downloads.betterthanadventure.net/bta-client/";
|
||||
private static final String CLIENT_JAR_URL = BASE_DOWNLOADS_URL + "%s/%s/client.jar";
|
||||
private static final String ICON_URL = BASE_DOWNLOADS_URL + "%s/%s/auto/%s.png";
|
||||
private static final String MANIFEST_URL = BASE_DOWNLOADS_URL + "%s/versions.json";
|
||||
private static final String BUILD_TYPE_RELEASE = "release";
|
||||
private static final String BUILD_TYPE_NIGHTLY = "nightly";
|
||||
private static final List<String> BTA_TESTED_VERSIONS = new ArrayList<>();
|
||||
static {
|
||||
BTA_TESTED_VERSIONS.add("v7.3");
|
||||
BTA_TESTED_VERSIONS.add("v7.2_01");
|
||||
BTA_TESTED_VERSIONS.add("v7.2");
|
||||
BTA_TESTED_VERSIONS.add("v7.1_01");
|
||||
BTA_TESTED_VERSIONS.add("v7.1");
|
||||
}
|
||||
|
||||
private static String getIconUrl(String version, String buildType) {
|
||||
String iconName = version.replace('.','_');
|
||||
if(buildType.equals("nightly")) iconName = "v"+iconName;
|
||||
return String.format(ICON_URL, buildType, version, iconName);
|
||||
}
|
||||
|
||||
private static String getClientJarUrl(String version, String buildType) {
|
||||
return String.format(CLIENT_JAR_URL, buildType, version);
|
||||
}
|
||||
|
||||
private static String getManifestUrl(String buildType) {
|
||||
return String.format(MANIFEST_URL, buildType);
|
||||
}
|
||||
|
||||
private static <T> T getManifest(String buildType, DownloadUtils.ParseCallback<T> parser)
|
||||
throws DownloadUtils.ParseException, IOException {
|
||||
String manifestUrl = getManifestUrl(buildType);
|
||||
return DownloadUtils.downloadStringCached(manifestUrl,"bta_"+manifestUrl, parser);
|
||||
}
|
||||
|
||||
private static List<BTAVersion> createVersionList(List<String> versionStrings, String buildType) {
|
||||
ListIterator<String> iterator = versionStrings.listIterator(versionStrings.size());
|
||||
ArrayList<BTAVersion> btaVersions = new ArrayList<>(versionStrings.size());
|
||||
// The original list is guaranteed to be in ascending order - the earliest versions
|
||||
// are at the top, but for user convenience we need to put the newest versions at the top,
|
||||
// so the BTAVersion list is made from the reverse of the string list.
|
||||
while(iterator.hasPrevious()) {
|
||||
String version = iterator.previous();
|
||||
if(version == null) continue;
|
||||
btaVersions.add(new BTAVersion(
|
||||
version,
|
||||
getClientJarUrl(version, buildType),
|
||||
getIconUrl(version, buildType)
|
||||
));
|
||||
}
|
||||
btaVersions.trimToSize();
|
||||
return btaVersions;
|
||||
}
|
||||
|
||||
private static List<BTAVersion> processNightliesJson(String nightliesInfo) throws JsonParseException {
|
||||
BTAVersionsManifest manifest = Tools.GLOBAL_GSON.fromJson(nightliesInfo, BTAVersionsManifest.class);
|
||||
return createVersionList(manifest.versions, BUILD_TYPE_NIGHTLY);
|
||||
}
|
||||
|
||||
private static BTAVersionList processReleasesJson(String releasesInfo) throws JsonParseException {
|
||||
BTAVersionsManifest manifest = Tools.GLOBAL_GSON.fromJson(releasesInfo, BTAVersionsManifest.class);
|
||||
List<String> stringVersions = manifest.versions;
|
||||
List<String> testedVersions = new ArrayList<>();
|
||||
List<String> untestedVersions = new ArrayList<>();
|
||||
for(String version : stringVersions) {
|
||||
if(version == null) break;
|
||||
// Checking for presence in testing array here to avoid accidentally adding nonexistent
|
||||
// versions if some of them end up getting removed.
|
||||
if(BTA_TESTED_VERSIONS.contains(version)) {
|
||||
testedVersions.add(version);
|
||||
}else {
|
||||
untestedVersions.add(version);
|
||||
}
|
||||
}
|
||||
|
||||
return new BTAVersionList(
|
||||
createVersionList(testedVersions, BUILD_TYPE_RELEASE),
|
||||
createVersionList(untestedVersions, BUILD_TYPE_RELEASE),
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
public static BTAVersionList downloadVersionList() throws IOException {
|
||||
try {
|
||||
BTAVersionList releases = getManifest(BUILD_TYPE_RELEASE, BTAUtils::processReleasesJson);
|
||||
List<BTAVersion> nightlies = getManifest(BUILD_TYPE_NIGHTLY, BTAUtils::processNightliesJson);
|
||||
return new BTAVersionList(releases.testedVersions, releases.untestedVersions, nightlies);
|
||||
}catch (DownloadUtils.ParseException e) {
|
||||
Log.e("BTAUtils", "Failed to process json", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static class BTAVersionsManifest {
|
||||
@Keep
|
||||
public List<String> versions;
|
||||
@Keep
|
||||
@SerializedName("default")
|
||||
public String defaultVersion;
|
||||
}
|
||||
|
||||
public static class BTAVersion {
|
||||
public final String versionName;
|
||||
public final String downloadUrl;
|
||||
public final String iconUrl;
|
||||
|
||||
public BTAVersion(String versionName, String downloadUrl, String iconUrl) {
|
||||
this.versionName = versionName;
|
||||
this.downloadUrl = downloadUrl;
|
||||
this.iconUrl = iconUrl;
|
||||
}
|
||||
}
|
||||
public static class BTAVersionList {
|
||||
public final List<BTAVersion> testedVersions;
|
||||
public final List<BTAVersion> untestedVersions;
|
||||
public final List<BTAVersion> nightlyVersions;
|
||||
|
||||
public BTAVersionList(List<BTAVersion> mTestedVersions, List<BTAVersion> mUntestedVersions, List<BTAVersion> nightlyVersions) {
|
||||
this.testedVersions = mTestedVersions;
|
||||
this.untestedVersions = mUntestedVersions;
|
||||
this.nightlyVersions = nightlyVersions;
|
||||
}
|
||||
}
|
||||
}
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
package net.kdt.pojavlaunch.modloaders;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseExpandableListAdapter;
|
||||
import android.widget.ExpandableListAdapter;
|
||||
import android.widget.TextView;
|
||||
|
||||
import net.kdt.pojavlaunch.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class BTAVersionListAdapter extends BaseExpandableListAdapter implements ExpandableListAdapter{
|
||||
private final LayoutInflater mLayoutInflater;
|
||||
private final ArrayList<String> mGroupNames;
|
||||
private final ArrayList<List<BTAUtils.BTAVersion>> mGroups;
|
||||
|
||||
public BTAVersionListAdapter(BTAUtils.BTAVersionList versionList, LayoutInflater mLayoutInflater) {
|
||||
this.mLayoutInflater = mLayoutInflater;
|
||||
Context context = mLayoutInflater.getContext();
|
||||
mGroupNames = new ArrayList<>(2);
|
||||
mGroups = new ArrayList<>(2);
|
||||
if(!versionList.testedVersions.isEmpty()) {
|
||||
mGroupNames.add(context.getString(R.string.bta_installer_available_versions));
|
||||
mGroups.add(versionList.testedVersions);
|
||||
}
|
||||
if(!versionList.untestedVersions.isEmpty()) {
|
||||
mGroupNames.add(context.getString(R.string.bta_installer_untested_versions));
|
||||
mGroups.add(versionList.untestedVersions);
|
||||
}
|
||||
if(!versionList.nightlyVersions.isEmpty()) {
|
||||
mGroupNames.add(context.getString(R.string.bta_installer_nightly_versions));
|
||||
mGroups.add(versionList.nightlyVersions);
|
||||
}
|
||||
mGroupNames.trimToSize();
|
||||
mGroups.trimToSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getGroupCount() {
|
||||
return mGroups.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getChildrenCount(int i) {
|
||||
return mGroups.get(i).size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getGroup(int i) {
|
||||
return mGroupNames.get(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BTAUtils.BTAVersion getChild(int i, int i1) {
|
||||
return mGroups.get(i).get(i1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getGroupId(int i) {
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getChildId(int i, int i1) {
|
||||
return i1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasStableIds() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getGroupView(int i, boolean b, View convertView, ViewGroup viewGroup) {
|
||||
if(convertView == null)
|
||||
convertView = mLayoutInflater.inflate(android.R.layout.simple_expandable_list_item_1, viewGroup, false);
|
||||
|
||||
((TextView) convertView).setText((String)getGroup(i));
|
||||
|
||||
return convertView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getChildView(int i, int i1, boolean b, View convertView, ViewGroup viewGroup) {
|
||||
if(convertView == null)
|
||||
convertView = mLayoutInflater.inflate(android.R.layout.simple_expandable_list_item_1, viewGroup, false);
|
||||
((TextView) convertView).setText(getChild(i,i1).versionName);
|
||||
return convertView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChildSelectable(int i, int i1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
-2
@@ -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));
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -111,6 +111,14 @@
|
||||
android:layout_marginTop="@dimen/padding_large"
|
||||
android:text="@string/modpack_install_button" />
|
||||
|
||||
<com.kdt.mcgui.MineButton
|
||||
android:id="@+id/modded_profile_bta"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="@dimen/padding_large"
|
||||
android:layout_marginTop="@dimen/padding_large"
|
||||
android:text="@string/create_bta_profile" />
|
||||
|
||||
<androidx.constraintlayout.widget.Guideline
|
||||
android:id="@+id/guideline"
|
||||
android:layout_width="wrap_content"
|
||||
|
||||
@@ -424,4 +424,10 @@
|
||||
<string name="local_login_bad_username_title">Unsuitable username</string>
|
||||
<string name="local_login_bad_username_text">The username must be between 3–16 characters long, and must only contain latin letters, numbers 0–9 and underscores.</string>
|
||||
<string name="quick_setting_title">Quick settings</string>
|
||||
<string name="create_bta_profile">Create \"Better than Adventure!\" profile</string>
|
||||
<string name="select_bta_version">Select \"Better than Adventure!\" version</string>
|
||||
<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;
|
||||
}
|
||||
@@ -1045,6 +1054,12 @@ public class GLFW
|
||||
nglfwSetShowingWindow(window);
|
||||
}
|
||||
|
||||
public static void glfwHideWindow(long window) {
|
||||
GLFWWindowProperties win = internalGetWindow(window);
|
||||
win.windowAttribs.put(GLFW_HOVERED, 0);
|
||||
win.windowAttribs.put(GLFW_VISIBLE, 0);
|
||||
}
|
||||
|
||||
public static void glfwWindowHint(int hint, int value) {
|
||||
if (hint == GLFW_VISIBLE) {
|
||||
mGLFWWindowVisibleOnCreation = value == GLFW_TRUE;
|
||||
@@ -1201,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} */
|
||||
@@ -1300,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) {
|
||||
@@ -1370,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) {
|
||||
|
||||
Reference in new issue
Block a user