Skip to content

Commit

Permalink
show message when game fails to load
Browse files Browse the repository at this point in the history
  • Loading branch information
qimiko committed Jan 19, 2024
1 parent e72a56a commit 0976a1b
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 25 deletions.
103 changes: 78 additions & 25 deletions app/src/main/java/com/geode/launcher/GeometryDashActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,32 +50,61 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL

// return back to main if Geometry Dash isn't found
if (!LaunchUtils.isGeometryDashInstalled(packageManager)) {
val launchIntent = Intent(this, MainActivity::class.java)
launchIntent.flags = Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK

startActivity(launchIntent)
returnToMain()
return
}

val gdPackageInfo = packageManager.getPackageInfo(Constants.PACKAGE_NAME, 0)

try {
LaunchUtils.addAssetsFromPackage(assets, gdPackageInfo)
} catch (e: NoSuchMethodException) {
tryLoadGame()
} catch (e: UnsatisfiedLinkError) {
e.printStackTrace()
}

try {
// fixes bugs specific to the new app directory, such as package name
val saveDir = LaunchUtils.getSaveDirectory(this)
saveDir.mkdir()
// generates helpful information for use in debugging library load failures
val gdPackageInfo = packageManager.getPackageInfo(Constants.PACKAGE_NAME, 0)

LauncherFix.loadLibrary()
LauncherFix.setOriginalDataPath(Constants.GJ_DATA_DIR)
LauncherFix.setDataPath(saveDir.path)
} catch (e: UnsatisfiedLinkError) {
val abi = LaunchUtils.applicationArchitecture
val isExtracted = gdPackageInfo.applicationInfo.flags and ApplicationInfo.FLAG_EXTRACT_NATIVE_LIBS == ApplicationInfo.FLAG_EXTRACT_NATIVE_LIBS
val isSplit = (gdPackageInfo.applicationInfo.splitSourceDirs?.size ?: 0) > 1

val metadata = "Geometry Dash metadata:\nSplit sources: $isSplit\nExtracted libraries: $isExtracted\nLauncher architecture: $abi"
Log.i("GeodeLauncher", metadata)

returnToMain(
getString(R.string.load_failed_link_error),
getString(R.string.load_failed_link_error_description)
)

return
} catch (e: Exception) {
e.printStackTrace()

returnToMain(
getString(R.string.load_failed_generic_error),
getString(R.string.load_failed_generic_error_description, e.message ?: "UnknownException")
)

return
}
}

private fun returnToMain(returnTitle: String? = null, returnMessage: String? = null) {
val launchIntent = Intent(this, MainActivity::class.java).apply {
flags = Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK

if (!returnTitle.isNullOrEmpty() && !returnMessage.isNullOrEmpty()) {
putExtra(Constants.LAUNCHER_KEY_RETURN_TITLE, returnTitle)
putExtra(Constants.LAUNCHER_KEY_RETURN_MESSAGE, returnMessage)
}
}

startActivity(launchIntent)
}

private fun tryLoadGame() {
val gdPackageInfo = packageManager.getPackageInfo(Constants.PACKAGE_NAME, 0)

setupRedirection(gdPackageInfo)

// request read and write permissions
requestPermissions(
arrayOf(
Expand All @@ -95,23 +124,47 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
loadTestingLibraries()
}

FMOD.init(this)

setContentView(createView())

setupPostLibraryLoad(gdPackageInfo)

if (!loadGeodeLibrary()) {
Log.w("GeodeLauncher", "could not load Geode object!")
}
}

private fun setupRedirection(packageInfo: PackageInfo) {
try {
LaunchUtils.addAssetsFromPackage(assets, packageInfo)
} catch (e: NoSuchMethodException) {
e.printStackTrace()
}

try {
// fixes bugs specific to the new app directory, such as package name
val saveDir = LaunchUtils.getSaveDirectory(this)
saveDir.mkdir()

LauncherFix.loadLibrary()
LauncherFix.setOriginalDataPath(Constants.GJ_DATA_DIR)
LauncherFix.setDataPath(saveDir.path)
} catch (e: UnsatisfiedLinkError) {
e.printStackTrace()
}
}

private fun setupPostLibraryLoad(packageInfo: PackageInfo) {
FMOD.init(this)

// call native functions after native libraries init
JniToCpp.setupHSSAssets(
gdPackageInfo.applicationInfo.sourceDir,
packageInfo.applicationInfo.sourceDir,
Environment.getExternalStorageDirectory().absolutePath
)
Cocos2dxHelper.nativeSetApkPath(gdPackageInfo.applicationInfo.sourceDir)
Cocos2dxHelper.nativeSetApkPath(packageInfo.applicationInfo.sourceDir)

BaseRobTopActivity.setCurrentActivity(this)
registerReceiver()

if (!loadGeodeLibrary()) {
Log.w("GeodeLauncher", "could not load Geode object!")
}
}

@SuppressLint("UnsafeDynamicallyLoadedCode")
Expand Down
31 changes: 31 additions & 0 deletions app/src/main/java/com/geode/launcher/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ class MainActivity : ComponentActivity() {
val gdInstalled = LaunchUtils.isGeometryDashInstalled(packageManager)
val geodeInstalled = LaunchUtils.isGeodeInstalled(this)

val returnMessage = intent.extras?.getString(Constants.LAUNCHER_KEY_RETURN_MESSAGE)
val returnTitle = intent.extras?.getString(Constants.LAUNCHER_KEY_RETURN_TITLE)

setContent {
val themeOption by PreferenceUtils.useIntPreference(PreferenceUtils.Key.THEME)
val theme = Theme.fromInt(themeOption)
Expand All @@ -68,6 +71,10 @@ class MainActivity : ComponentActivity() {
color = MaterialTheme.colorScheme.background
) {
MainScreen(gdInstalled, geodeInstalled)

if (!returnMessage.isNullOrEmpty() && !returnTitle.isNullOrEmpty()) {
LoadFailedDialog(returnTitle, returnMessage)
}
}
}
}
Expand Down Expand Up @@ -146,6 +153,30 @@ fun UpdateMessageIndicator(

}

@Composable
fun LoadFailedDialog(returnTitle: String, returnMessage: String) {
var showDialog by remember { mutableStateOf(true) }

if (showDialog) {
AlertDialog(
icon = {
Icon(
painterResource(R.drawable.icon_error),
contentDescription = stringResource(R.string.launcher_error_icon_alt)
)
},
title = { Text(returnTitle) },
text = { Text(returnMessage) },
confirmButton = {
TextButton(onClick = { showDialog = false }) {
Text(stringResource(R.string.message_box_accept))
}
},
onDismissRequest = { showDialog = false }
)
}
}

@Composable
fun UpdateWarning() {
val context = LocalContext.current
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/com/geode/launcher/utils/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ object Constants {

const val SUPPORTED_VERSION_CODE = 37L
const val SUPPORTED_VERSION_STRING = "2.2.13"

const val LAUNCHER_KEY_RETURN_TITLE = "return_title"
const val LAUNCHER_KEY_RETURN_MESSAGE = "return_message"

}
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/icon_error.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M480,680Q497,680 508.5,668.5Q520,657 520,640Q520,623 508.5,611.5Q497,600 480,600Q463,600 451.5,611.5Q440,623 440,640Q440,657 451.5,668.5Q463,680 480,680ZM440,520L520,520L520,280L440,280L440,520ZM480,880Q397,880 324,848.5Q251,817 197,763Q143,709 111.5,636Q80,563 80,480Q80,397 111.5,324Q143,251 197,197Q251,143 324,111.5Q397,80 480,80Q563,80 636,111.5Q709,143 763,197Q817,251 848.5,324Q880,397 880,480Q880,563 848.5,636Q817,709 763,763Q709,817 636,848.5Q563,880 480,880ZM480,800Q614,800 707,707Q800,614 800,480Q800,346 707,253Q614,160 480,160Q346,160 253,253Q160,346 160,480Q160,614 253,707Q346,800 480,800ZM480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Z"/>
</vector>
5 changes: 5 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<item quantity="other">Automatically launching game in %1$d seconds.</item>
</plurals>
<string name="launcher_warning_icon_alt">warning</string>
<string name="launcher_error_icon_alt">error</string>
<string name="launcher_unsupported_version_title">Unsupported version</string>
<string name="launcher_unsupported_version_description">
The current version of Geometry Dash is not compatible with the version supported by the launcher (%2$s).\nLaunch will continue, but crashes may occur!
Expand All @@ -38,6 +39,10 @@
<string name="release_fetch_manual_check_required">Externally managed library in use, please manually check for updates if you want to overwrite it.</string>

<!-- GeometryDashActivity strings -->
<string name="load_failed_link_error">Failed to link libraries</string>
<string name="load_failed_link_error_description">Game libraries could not be found. This may occur if the architecture of the launcher and Geometry Dash do not match, or from a system bug.\nCheck application logs for more details. Please report this issue!</string>
<string name="load_failed_generic_error">Load failed</string>
<string name="load_failed_generic_error_description">Uncaught error during game load: `%1$s`.\nCheck application logs for more details. Please report this issue!</string>
<string name="message_box_cancel">Cancel</string>
<string name="message_box_accept">OK</string>

Expand Down

0 comments on commit 0976a1b

Please sign in to comment.