mirror of
https://github.com/geode-sdk/android-launcher.git
synced 2026-10-22 08:42:38 +00:00
add ability to load mods from assets
this replaces the old "load testing libraries" option, which hasn't been available in the ui anyways
This commit is contained in:
1 file changed
+34
-39
@@ -35,6 +35,7 @@ import org.fmod.FMOD
|
|||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileInputStream
|
import java.io.FileInputStream
|
||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
|
import java.io.IOException
|
||||||
|
|
||||||
enum class DisplayMode {
|
enum class DisplayMode {
|
||||||
DEFAULT, LIMITED, FULLSCREEN;
|
DEFAULT, LIMITED, FULLSCREEN;
|
||||||
@@ -132,9 +133,7 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
|
|||||||
tryLoadLibrary(gdPackageInfo, Constants.FMOD_LIB_NAME)
|
tryLoadLibrary(gdPackageInfo, Constants.FMOD_LIB_NAME)
|
||||||
tryLoadLibrary(gdPackageInfo, Constants.COCOS_LIB_NAME)
|
tryLoadLibrary(gdPackageInfo, Constants.COCOS_LIB_NAME)
|
||||||
|
|
||||||
if (getLoadTesting()) {
|
loadInternalMods()
|
||||||
loadTestingLibraries()
|
|
||||||
}
|
|
||||||
|
|
||||||
setContentView(createView())
|
setContentView(createView())
|
||||||
|
|
||||||
@@ -513,42 +512,6 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
|
|||||||
return isEmulator
|
return isEmulator
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getLoadTesting(): Boolean {
|
|
||||||
val preferences = PreferenceUtils.get(this)
|
|
||||||
return preferences.getBoolean(PreferenceUtils.Key.LOAD_TESTING)
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressLint("UnsafeDynamicallyLoadedCode")
|
|
||||||
private fun loadTestingLibraries() {
|
|
||||||
// clear data dir
|
|
||||||
val testDirPath = File(filesDir.path + File.separator + "testlib" + File.separator)
|
|
||||||
if (testDirPath.exists()) {
|
|
||||||
testDirPath.deleteRecursively()
|
|
||||||
}
|
|
||||||
testDirPath.mkdir()
|
|
||||||
|
|
||||||
val dir = LaunchUtils.getBaseDirectory(this)
|
|
||||||
val testingPath = File(dir, "test")
|
|
||||||
|
|
||||||
testingPath.walk().forEach {
|
|
||||||
if (it.isFile) {
|
|
||||||
// welcome to the world of Android classloader permissions
|
|
||||||
val outputFile = File(testDirPath, it.name)
|
|
||||||
DownloadUtils.copyFile(
|
|
||||||
FileInputStream(it),
|
|
||||||
FileOutputStream(outputFile)
|
|
||||||
)
|
|
||||||
|
|
||||||
try {
|
|
||||||
println("Loading test library ${outputFile.name}")
|
|
||||||
System.load(outputFile.path)
|
|
||||||
} catch (e: UnsatisfiedLinkError) {
|
|
||||||
e.printStackTrace()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCapabilityAdded(capability: String): Boolean {
|
override fun onCapabilityAdded(capability: String): Boolean {
|
||||||
if (capability == GeodeUtils.CAPABILITY_EXTENDED_INPUT) {
|
if (capability == GeodeUtils.CAPABILITY_EXTENDED_INPUT) {
|
||||||
mGLSurfaceView?.useKeyboardEvents = true
|
mGLSurfaceView?.useKeyboardEvents = true
|
||||||
@@ -557,4 +520,36 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
|
|||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies a mod from the launcher's assets to the Geode mods directory.
|
||||||
|
* This method is not recommended for casual use, the new mod will not be automatically removed.
|
||||||
|
*/
|
||||||
|
private fun loadInternalMods() {
|
||||||
|
val internalModBase = "mods"
|
||||||
|
|
||||||
|
val modListing = try {
|
||||||
|
assets.list(internalModBase)
|
||||||
|
} catch (ioe: IOException) {
|
||||||
|
emptyArray<String>()
|
||||||
|
}
|
||||||
|
|
||||||
|
val modDirectory = File(
|
||||||
|
LaunchUtils.getBaseDirectory(this),
|
||||||
|
"game/geode/mods"
|
||||||
|
)
|
||||||
|
|
||||||
|
modDirectory.mkdirs()
|
||||||
|
|
||||||
|
modListing?.forEach { fileName ->
|
||||||
|
if (fileName.endsWith(".geode")) {
|
||||||
|
val modOutput = File(modDirectory, fileName)
|
||||||
|
|
||||||
|
val mod = assets.open("$internalModBase/$fileName")
|
||||||
|
DownloadUtils.copyFile(mod, modOutput.outputStream())
|
||||||
|
|
||||||
|
println("Copied internal mod $fileName")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user