Merge pull request #10369 from Simonx22/android-online-system-update-2

Android: Add online system update functionality
This commit is contained in:
JMC47
2022-01-22 14:46:42 -05:00
committed by GitHub
21 changed files with 698 additions and 23 deletions

View File

@ -73,6 +73,9 @@ static jmethodID s_patch_cheat_constructor;
static jclass s_riivolution_patches_class;
static jfieldID s_riivolution_patches_pointer;
static jclass s_wii_update_cb_class;
static jmethodID s_wii_update_cb_run;
namespace IDCache
{
JNIEnv* GetEnvForThread()
@ -338,6 +341,16 @@ jfieldID GetRiivolutionPatchesPointer()
return s_riivolution_patches_pointer;
}
jclass GetWiiUpdateCallbackClass()
{
return s_wii_update_cb_class;
}
jmethodID GetWiiUpdateCallbackFunction()
{
return s_wii_update_cb_run;
}
} // namespace IDCache
extern "C" {
@ -474,6 +487,12 @@ JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved)
s_riivolution_patches_pointer = env->GetFieldID(riivolution_patches_class, "mPointer", "J");
env->DeleteLocalRef(riivolution_patches_class);
const jclass wii_update_cb_class =
env->FindClass("org/dolphinemu/dolphinemu/utils/WiiUpdateCallback");
s_wii_update_cb_class = reinterpret_cast<jclass>(env->NewGlobalRef(wii_update_cb_class));
s_wii_update_cb_run = env->GetMethodID(s_wii_update_cb_class, "run", "(IIJ)Z");
env->DeleteLocalRef(wii_update_cb_class);
return JNI_VERSION;
}
@ -498,5 +517,6 @@ JNIEXPORT void JNI_OnUnload(JavaVM* vm, void* reserved)
env->DeleteGlobalRef(s_gecko_cheat_class);
env->DeleteGlobalRef(s_patch_cheat_class);
env->DeleteGlobalRef(s_riivolution_patches_class);
env->DeleteGlobalRef(s_wii_update_cb_class);
}
}

View File

@ -72,4 +72,7 @@ jmethodID GetPatchCheatConstructor();
jclass GetRiivolutionPatchesClass();
jfieldID GetRiivolutionPatchesPointer();
jclass GetWiiUpdateCallbackClass();
jmethodID GetWiiUpdateCallbackFunction();
} // namespace IDCache

View File

@ -32,6 +32,7 @@
#include "Core/Boot/Boot.h"
#include "Core/BootManager.h"
#include "Core/CommonTitles.h"
#include "Core/ConfigLoaders/GameConfigLoader.h"
#include "Core/ConfigManager.h"
#include "Core/Core.h"
@ -547,21 +548,14 @@ static float GetRenderSurfaceScale(JNIEnv* env)
return env->CallStaticFloatMethod(native_library_class, get_render_surface_scale_method);
}
static void Run(JNIEnv* env, const std::vector<std::string>& paths, bool riivolution,
BootSessionData boot_session_data = BootSessionData())
static void Run(JNIEnv* env, std::unique_ptr<BootParameters>&& boot, bool riivolution)
{
ASSERT(!paths.empty());
__android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Running : %s", paths[0].c_str());
std::unique_lock<std::mutex> host_identity_guard(s_host_identity_lock);
WiimoteReal::InitAdapterClass();
s_have_wm_user_stop = false;
std::unique_ptr<BootParameters> boot =
BootParameters::GenerateFromFile(paths, std::move(boot_session_data));
if (riivolution && std::holds_alternative<BootParameters::Disc>(boot->parameters))
{
const std::string& riivolution_dir = File::GetUserPath(D_RIIVOLUTION_IDX);
@ -624,6 +618,15 @@ static void Run(JNIEnv* env, const std::vector<std::string>& paths, bool riivolu
IDCache::GetFinishEmulationActivity());
}
static void Run(JNIEnv* env, const std::vector<std::string>& paths, bool riivolution,
BootSessionData boot_session_data = BootSessionData())
{
ASSERT(!paths.empty());
__android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Running : %s", paths[0].c_str());
Run(env, BootParameters::GenerateFromFile(paths, std::move(boot_session_data)), riivolution);
}
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Run___3Ljava_lang_String_2Z(
JNIEnv* env, jclass, jobjectArray jPaths, jboolean jRiivolution)
{
@ -641,6 +644,12 @@ Java_org_dolphinemu_dolphinemu_NativeLibrary_Run___3Ljava_lang_String_2ZLjava_la
BootSessionData(GetJString(env, jSavestate), delete_state));
}
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_RunSystemMenu(JNIEnv* env,
jclass)
{
Run(env, std::make_unique<BootParameters>(BootParameters::NANDTitle{Titles::SYSTEM_MENU}), false);
}
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_ChangeDisc(JNIEnv* env, jclass,
jstring jFile)
{

View File

@ -8,7 +8,11 @@
#include "jni/AndroidCommon/AndroidCommon.h"
#include "jni/AndroidCommon/IDCache.h"
#include "Common/ScopeGuard.h"
#include "Core/CommonTitles.h"
#include "Core/HW/WiiSave.h"
#include "Core/IOS/ES/ES.h"
#include "Core/IOS/IOS.h"
#include "Core/WiiUtils.h"
#include "DiscIO/NANDImporter.h"
@ -35,6 +39,36 @@ static jint ConvertCopyResult(WiiSave::CopyResult result)
static_assert(static_cast<int>(WiiSave::CopyResult::NumberOfEntries) == 5);
}
static jint ConvertUpdateResult(WiiUtils::UpdateResult result)
{
switch (result)
{
case WiiUtils::UpdateResult::Succeeded:
return 0;
case WiiUtils::UpdateResult::AlreadyUpToDate:
return 1;
case WiiUtils::UpdateResult::RegionMismatch:
return 2;
case WiiUtils::UpdateResult::MissingUpdatePartition:
return 3;
case WiiUtils::UpdateResult::DiscReadFailed:
return 4;
case WiiUtils::UpdateResult::ServerFailed:
return 5;
case WiiUtils::UpdateResult::DownloadFailed:
return 6;
case WiiUtils::UpdateResult::ImportFailed:
return 7;
case WiiUtils::UpdateResult::Cancelled:
return 8;
default:
ASSERT(false);
return 1;
}
static_assert(static_cast<int>(WiiUtils::UpdateResult::NumberOfEntries) == 9);
}
extern "C" {
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_utils_WiiUtils_installWAD(JNIEnv* env,
@ -78,4 +112,46 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_utils_WiiUtils_importNANDB
return "";
});
}
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_utils_WiiUtils_doOnlineUpdate(
JNIEnv* env, jclass, jstring jRegion, jobject jCallback)
{
const std::string region = GetJString(env, jRegion);
jobject jCallbackGlobal = env->NewGlobalRef(jCallback);
Common::ScopeGuard scope_guard([jCallbackGlobal, env] { env->DeleteGlobalRef(jCallbackGlobal); });
const auto callback = [&jCallbackGlobal](int processed, int total, u64 title_id) {
JNIEnv* env = IDCache::GetEnvForThread();
return static_cast<bool>(env->CallBooleanMethod(
jCallbackGlobal, IDCache::GetWiiUpdateCallbackFunction(), processed, total, title_id));
};
WiiUtils::UpdateResult result = WiiUtils::DoOnlineUpdate(callback, region);
return ConvertUpdateResult(result);
}
JNIEXPORT jboolean JNICALL
Java_org_dolphinemu_dolphinemu_utils_WiiUtils_isSystemMenuInstalled(JNIEnv* env, jclass)
{
IOS::HLE::Kernel ios;
const auto tmd = ios.GetES()->FindInstalledTMD(Titles::SYSTEM_MENU);
return tmd.IsValid();
}
JNIEXPORT jstring JNICALL
Java_org_dolphinemu_dolphinemu_utils_WiiUtils_getSystemMenuVersion(JNIEnv* env, jclass)
{
IOS::HLE::Kernel ios;
const auto tmd = ios.GetES()->FindInstalledTMD(Titles::SYSTEM_MENU);
if (!tmd.IsValid())
{
return ToJString(env, "");
}
return ToJString(env, DiscIO::GetSysMenuVersionString(tmd.GetTitleVersion()));
}
}