Android: Get game metadata from core

Trying to get it from a GameFile before emulation starts is unreliable.
This commit is contained in:
JosJuice
2020-09-13 13:20:58 +02:00
parent b6fcfcb9c9
commit 0dc29c743b
13 changed files with 158 additions and 114 deletions

View File

@ -13,7 +13,8 @@ static JavaVM* s_java_vm;
static jclass s_native_library_class;
static jmethodID s_display_alert_msg;
static jmethodID s_do_rumble;
static jmethodID s_get_update_touch_pointer;
static jmethodID s_update_touch_pointer;
static jmethodID s_on_title_changed;
static jclass s_game_file_class;
static jfieldID s_game_file_pointer;
@ -85,7 +86,12 @@ jmethodID GetDoRumble()
jmethodID GetUpdateTouchPointer()
{
return s_get_update_touch_pointer;
return s_update_touch_pointer;
}
jmethodID GetOnTitleChanged()
{
return s_on_title_changed;
}
jclass GetAnalyticsClass()
@ -212,8 +218,9 @@ jint JNI_OnLoad(JavaVM* vm, void* reserved)
s_display_alert_msg = env->GetStaticMethodID(s_native_library_class, "displayAlertMsg",
"(Ljava/lang/String;Ljava/lang/String;ZZ)Z");
s_do_rumble = env->GetStaticMethodID(s_native_library_class, "rumble", "(ID)V");
s_get_update_touch_pointer =
s_update_touch_pointer =
env->GetStaticMethodID(s_native_library_class, "updateTouchPointer", "()V");
s_on_title_changed = env->GetStaticMethodID(s_native_library_class, "onTitleChanged", "()V");
env->DeleteLocalRef(native_library_class);
const jclass game_file_class = env->FindClass("org/dolphinemu/dolphinemu/model/GameFile");

View File

@ -16,6 +16,7 @@ jclass GetNativeLibraryClass();
jmethodID GetDisplayAlertMsg();
jmethodID GetDoRumble();
jmethodID GetUpdateTouchPointer();
jmethodID GetOnTitleChanged();
jclass GetAnalyticsClass();
jmethodID GetSendAnalyticsReport();

View File

@ -80,6 +80,7 @@ std::mutex s_host_identity_lock;
Common::Event s_update_main_frame_event;
Common::Event s_emulation_end_event;
bool s_have_wm_user_stop = false;
bool s_game_metadata_is_valid = false;
} // Anonymous namespace
void UpdatePointer()
@ -149,6 +150,10 @@ void Host_YieldToUI()
void Host_TitleChanged()
{
s_game_metadata_is_valid = true;
JNIEnv* env = IDCache::GetEnvForThread();
env->CallStaticVoidMethod(IDCache::GetNativeLibraryClass(), IDCache::GetOnTitleChanged());
}
static bool MsgAlert(const char* caption, const char* text, bool yes_no, Common::MsgType style)
@ -608,6 +613,7 @@ static void Run(JNIEnv* env, const std::vector<std::string>& paths,
}
}
s_game_metadata_is_valid = false;
Core::Shutdown();
ButtonManager::Shutdown();
guard.unlock();
@ -752,6 +758,31 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetObscuredP
OSD::SetObscuredPixelsTop(height);
}
JNIEXPORT jboolean JNICALL
Java_org_dolphinemu_dolphinemu_NativeLibrary_IsGameMetadataValid(JNIEnv* env, jobject obj)
{
return s_game_metadata_is_valid;
}
JNIEXPORT jboolean JNICALL
Java_org_dolphinemu_dolphinemu_NativeLibrary_IsEmulatingWiiUnchecked(JNIEnv* env, jobject obj)
{
return SConfig::GetInstance().bWii;
}
JNIEXPORT jstring JNICALL
Java_org_dolphinemu_dolphinemu_NativeLibrary_GetCurrentGameIDUnchecked(JNIEnv* env, jobject obj)
{
return ToJString(env, SConfig::GetInstance().GetGameID());
}
JNIEXPORT jstring JNICALL
Java_org_dolphinemu_dolphinemu_NativeLibrary_GetCurrentTitleDescriptionUnchecked(JNIEnv* env,
jobject obj)
{
return ToJString(env, SConfig::GetInstance().GetTitleDescription());
}
#ifdef __cplusplus
}
#endif