fix application directory

This commit is contained in:
qimiko committed 2022-05-27 21:20:07 -07:00
1 parent 332069bc92
commit 3cba74c4bc
8 files changed
+136 -1

No files matched your search

+11
View File
@@ -17,6 +17,11 @@ android {
vectorDrawables {
useSupportLibrary true
}
externalNativeBuild {
cmake {
arguments "-DDOBBY_DEBUG=OFF"
}
}
}
buildTypes {
@@ -43,6 +48,12 @@ android {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
externalNativeBuild {
cmake {
path file('src/main/cpp/CMakeLists.txt')
version '3.18.1'
}
}
}
dependencies {
+26
View File
@@ -0,0 +1,26 @@
cmake_minimum_required(VERSION 3.18.1)
project(launcherfix)
add_library(launcherfix SHARED launcher-fix.cpp)
find_library(log-lib log)
target_link_libraries(launcherfix ${log-lib})
include(FetchContent)
FetchContent_Declare(dobby
GIT_REPOSITORY https://github.com/jmpews/Dobby
GIT_TAG 223aabced0431525c7d45196f9409fc505d58ac8)
FetchContent_GetProperties(dobby)
if(NOT dobby_POPULATED)
FetchContent_Populate(dobby)
set(DOBBY_DEBUG OFF CACHE INTERNAL "" FORCE)
set(DOBBY_GENERATE_SHARED OFF CACHE INTERNAL "" FORCE)
add_subdirectory("${dobby_SOURCE_DIR}" ${dobby_BINARY_DIR} EXCLUDE_FROM_ALL)
target_include_directories(launcherfix PRIVATE ${dobby_SOURCE_DIR}/include)
target_link_libraries(launcherfix dobby)
endif()
+71
View File
@@ -0,0 +1,71 @@
#include <dlfcn.h>
#include <android/log.h>
#include <string>
#include <dobby.h>
#include <jni.h>
class DataPaths {
public:
std::string original_data_path;
std::string data_path;
static DataPaths& get_instance() {
static auto paths_instance = DataPaths();
return paths_instance;
}
private:
DataPaths() : original_data_path(), data_path() {}
};
extern "C"
JNIEXPORT void JNICALL Java_dev_xyze_geodelauncher_LauncherFix_setDataPath(
JNIEnv *env,
jobject,
jstring data_path
) {
auto is_copy = jboolean();
auto data_path_str = env->GetStringUTFChars(data_path, &is_copy);
DataPaths::get_instance().data_path = std::string(data_path_str);
}
extern "C"
JNIEXPORT void JNICALL Java_dev_xyze_geodelauncher_LauncherFix_setOriginalDataPath(
JNIEnv *env,
jobject,
jstring data_path
) {
auto is_copy = jboolean();
auto data_path_str = env->GetStringUTFChars(data_path, &is_copy);
DataPaths::get_instance().original_data_path = std::string(data_path_str);
}
FILE* (*fopen_original)(const char *pathname, const char *mode);
FILE* fopen_hook(const char* pathname, const char* mode) {
auto data_path = DataPaths::get_instance().data_path;
auto original_data_path = DataPaths::get_instance().original_data_path;
if (!data_path.empty() && !original_data_path.empty()) {
auto path_str = std::string(pathname);
auto pos = path_str.find(original_data_path);
if (pos != std::string::npos) {
path_str.replace(pos, original_data_path.length(), data_path);
}
return fopen_original(path_str.c_str(), mode);
}
return fopen_original(pathname, mode);
}
[[gnu::constructor]] [[gnu::used]] void setup_hooks() {
auto fopen_addr = dlsym(RTLD_NEXT, "fopen");
DobbyHook(
fopen_addr,
reinterpret_cast<void*>(&fopen_hook),
reinterpret_cast<void**>(&fopen_original)
);
}
@@ -61,6 +61,15 @@ class GeometryDashActivity : ComponentActivity(), Cocos2dxHelper.Cocos2dxHelperL
e.printStackTrace()
}
try {
// fixes bugs specific to the new app directory, such as package name
LauncherFix.loadLibrary()
LauncherFix.setOriginalDataPath(GJConstants.GJ_DATA_DIR)
LauncherFix.setDataPath(filesDir.path)
} catch (e: UnsatisfiedLinkError) {
e.printStackTrace()
}
System.load("$gdNativeLibraryPath/lib${GJConstants.FMOD_LIB_NAME}.so")
System.load("$gdNativeLibraryPath/lib${GJConstants.COCOS_LIB_NAME}.so")
@@ -0,0 +1,13 @@
package dev.xyze.geodelauncher
import dev.xyze.geodelauncher.utils.GJConstants
object LauncherFix {
fun loadLibrary() {
System.loadLibrary(GJConstants.LAUNCHER_FIX_LIB_NAME)
}
external fun setDataPath(dataPath: String);
external fun setOriginalDataPath(dataPath: String);
}
@@ -6,4 +6,8 @@ object GJConstants {
const val COCOS_LIB_NAME = "cocos2dcpp"
const val FMOD_LIB_NAME = "fmod"
const val MOD_CORE_LIB_NAME = "geode"
const val LAUNCHER_FIX_LIB_NAME = "launcherfix"
// this value is hardcoded into GD
const val GJ_DATA_DIR = "/data/data/${PACKAGE_NAME}"
}
@@ -14,6 +14,7 @@ import java.util.*
import kotlin.math.abs
import kotlin.math.ceil
@Suppress("KotlinJniMissingFunction")
object Cocos2dxBitmap {
private lateinit var sContext: WeakReference<Context>
@@ -4,7 +4,7 @@ import android.opengl.GLSurfaceView
import javax.microedition.khronos.egl.EGLConfig
import javax.microedition.khronos.opengles.GL10
@Suppress("unused")
@Suppress("unused", "KotlinJniMissingFunction")
class Cocos2dxRenderer : GLSurfaceView.Renderer {
companion object {
@JvmStatic