2015-05-25 11:11:41 +00:00
|
|
|
// Copyright 2003 Dolphin Emulator Project
|
2015-05-17 23:08:10 +00:00
|
|
|
// Licensed under GPLv2+
|
2015-05-25 11:11:41 +00:00
|
|
|
// Refer to the license.txt file included.
|
2013-02-26 19:49:00 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
#include <EGL/egl.h>
|
|
|
|
#include <android/log.h>
|
|
|
|
#include <android/native_window_jni.h>
|
2015-12-07 09:13:25 +00:00
|
|
|
#include <cinttypes>
|
2014-02-19 01:56:29 +00:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <jni.h>
|
2015-12-07 04:15:51 +00:00
|
|
|
#include <memory>
|
2016-05-12 01:18:30 +00:00
|
|
|
#include <mutex>
|
2017-12-26 21:08:44 +00:00
|
|
|
#include <optional>
|
2017-05-18 23:33:44 +00:00
|
|
|
#include <string>
|
2016-05-12 09:17:17 +00:00
|
|
|
#include <thread>
|
2017-12-28 09:13:53 +00:00
|
|
|
#include <utility>
|
2015-12-07 09:13:25 +00:00
|
|
|
|
2016-01-06 21:35:15 +00:00
|
|
|
#include "ButtonManager.h"
|
2015-12-07 09:13:25 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
#include "Common/CPUDetect.h"
|
2014-02-22 22:36:30 +00:00
|
|
|
#include "Common/CommonPaths.h"
|
2014-09-08 01:06:58 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2014-04-13 23:15:23 +00:00
|
|
|
#include "Common/Event.h"
|
2014-02-19 01:56:29 +00:00
|
|
|
#include "Common/FileUtil.h"
|
2016-01-10 18:31:49 +00:00
|
|
|
#include "Common/GL/GLInterfaceBase.h"
|
2014-06-05 23:29:54 +00:00
|
|
|
#include "Common/Logging/LogManager.h"
|
2017-05-22 08:39:36 +00:00
|
|
|
#include "Common/MsgHandler.h"
|
2017-09-09 19:52:35 +00:00
|
|
|
#include "Common/Version.h"
|
2015-12-07 09:13:25 +00:00
|
|
|
|
2017-05-27 13:43:40 +00:00
|
|
|
#include "Core/Boot/Boot.h"
|
2014-02-19 01:56:29 +00:00
|
|
|
#include "Core/BootManager.h"
|
2018-02-16 18:47:52 +00:00
|
|
|
#include "Core/ConfigLoaders/GameConfigLoader.h"
|
2014-02-19 01:56:29 +00:00
|
|
|
#include "Core/ConfigManager.h"
|
|
|
|
#include "Core/Core.h"
|
2018-01-21 00:31:53 +00:00
|
|
|
#include "Core/HW/DVD/DVDInterface.h"
|
2014-02-19 01:56:29 +00:00
|
|
|
#include "Core/HW/Wiimote.h"
|
2016-02-05 00:31:36 +00:00
|
|
|
#include "Core/HW/WiimoteReal/WiimoteReal.h"
|
2016-06-24 08:43:46 +00:00
|
|
|
#include "Core/Host.h"
|
2015-05-11 01:03:34 +00:00
|
|
|
#include "Core/PowerPC/JitInterface.h"
|
2017-04-15 14:23:48 +00:00
|
|
|
#include "Core/PowerPC/PowerPC.h"
|
2015-05-11 01:03:34 +00:00
|
|
|
#include "Core/PowerPC/Profiler.h"
|
2016-06-24 08:43:46 +00:00
|
|
|
#include "Core/State.h"
|
2013-04-15 01:39:56 +00:00
|
|
|
|
2016-07-06 18:33:05 +00:00
|
|
|
#include "DiscIO/Enums.h"
|
2015-12-07 09:13:25 +00:00
|
|
|
#include "DiscIO/Volume.h"
|
2013-04-23 19:21:48 +00:00
|
|
|
|
2014-10-04 19:12:15 +00:00
|
|
|
#include "UICommon/UICommon.h"
|
|
|
|
|
2014-02-19 01:56:29 +00:00
|
|
|
#include "VideoCommon/OnScreenDisplay.h"
|
2015-06-19 01:28:40 +00:00
|
|
|
#include "VideoCommon/RenderBase.h"
|
2014-02-19 01:56:29 +00:00
|
|
|
#include "VideoCommon/VideoBackendBase.h"
|
2013-02-26 19:49:00 +00:00
|
|
|
|
2017-05-18 23:33:44 +00:00
|
|
|
#define DOLPHIN_TAG "DolphinEmuNative"
|
2013-07-27 20:09:18 +00:00
|
|
|
|
2015-06-08 00:13:52 +00:00
|
|
|
JavaVM* g_java_vm;
|
|
|
|
|
2017-05-18 23:33:44 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
ANativeWindow* s_surf;
|
|
|
|
|
|
|
|
jclass s_jni_class;
|
|
|
|
jmethodID s_jni_method_alert;
|
|
|
|
|
|
|
|
// The Core only supports using a single Host thread.
|
|
|
|
// If multiple threads want to call host functions then they need to queue
|
|
|
|
// sequentially for access.
|
|
|
|
std::mutex s_host_identity_lock;
|
|
|
|
Common::Event s_update_main_frame_event;
|
|
|
|
bool s_have_wm_user_stop = false;
|
|
|
|
} // Anonymous namespace
|
2013-02-26 19:49:00 +00:00
|
|
|
|
2015-06-08 00:13:52 +00:00
|
|
|
/*
|
|
|
|
* Cache the JavaVM so that we can call into it later.
|
|
|
|
*/
|
|
|
|
jint JNI_OnLoad(JavaVM* vm, void* reserved)
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
g_java_vm = vm;
|
2015-06-08 00:13:52 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
return JNI_VERSION_1_6;
|
2015-06-08 00:13:52 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
void Host_NotifyMapLoaded()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
void Host_RefreshDSPDebuggerWindow()
|
|
|
|
{
|
|
|
|
}
|
2013-02-26 19:49:00 +00:00
|
|
|
|
|
|
|
void Host_Message(int Id)
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
if (Id == WM_USER_JOB_DISPATCH)
|
|
|
|
{
|
2017-05-18 23:33:44 +00:00
|
|
|
s_update_main_frame_event.Set();
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
|
|
|
else if (Id == WM_USER_STOP)
|
|
|
|
{
|
|
|
|
s_have_wm_user_stop = true;
|
|
|
|
if (Core::IsRunning())
|
|
|
|
Core::QueueHostJob(&Core::Stop);
|
|
|
|
}
|
2013-02-26 19:49:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void* Host_GetRenderHandle()
|
|
|
|
{
|
2017-05-18 23:33:44 +00:00
|
|
|
return s_surf;
|
2013-02-26 19:49:00 +00:00
|
|
|
}
|
|
|
|
|
2014-03-12 19:33:41 +00:00
|
|
|
void Host_UpdateTitle(const std::string& title)
|
2013-07-27 20:09:18 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
__android_log_write(ANDROID_LOG_INFO, DOLPHIN_TAG, title.c_str());
|
2014-03-17 23:17:12 +00:00
|
|
|
}
|
2013-02-26 19:49:00 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
void Host_UpdateDisasmDialog()
|
|
|
|
{
|
|
|
|
}
|
2013-02-26 19:49:00 +00:00
|
|
|
|
|
|
|
void Host_UpdateMainFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
void Host_RequestRenderWindowSize(int width, int height)
|
|
|
|
{
|
|
|
|
}
|
2014-07-16 13:53:33 +00:00
|
|
|
|
2013-02-26 19:49:00 +00:00
|
|
|
void Host_SetStartupDebuggingParameters()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-07-12 07:11:29 +00:00
|
|
|
bool Host_UINeedsControllerState()
|
2014-07-16 14:24:40 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
return true;
|
2014-07-16 14:24:40 +00:00
|
|
|
}
|
|
|
|
|
2013-02-26 19:49:00 +00:00
|
|
|
bool Host_RendererHasFocus()
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
return true;
|
2013-02-26 19:49:00 +00:00
|
|
|
}
|
|
|
|
|
2015-01-04 16:09:56 +00:00
|
|
|
bool Host_RendererIsFullscreen()
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
return false;
|
2015-01-04 16:09:56 +00:00
|
|
|
}
|
|
|
|
|
2016-06-26 06:06:23 +00:00
|
|
|
void Host_ShowVideoConfig(void*, const std::string&)
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
|
|
|
}
|
2014-08-02 06:21:03 +00:00
|
|
|
|
2016-11-10 16:55:21 +00:00
|
|
|
void Host_YieldToUI()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-06-25 15:35:24 +00:00
|
|
|
void Host_UpdateProgressDialog(const char* caption, int position, int total)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-07-26 04:11:17 +00:00
|
|
|
static bool MsgAlert(const char* caption, const char* text, bool yes_no, MsgType /*style*/)
|
2015-02-13 00:41:52 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
__android_log_print(ANDROID_LOG_ERROR, DOLPHIN_TAG, "%s:%s", caption, text);
|
2015-06-08 00:13:52 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
// Associate the current Thread with the Java VM.
|
|
|
|
JNIEnv* env;
|
|
|
|
g_java_vm->AttachCurrentThread(&env, NULL);
|
2015-06-08 00:13:52 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
// Execute the Java method.
|
2018-01-07 22:30:28 +00:00
|
|
|
jboolean result =
|
|
|
|
env->CallStaticBooleanMethod(s_jni_class, s_jni_method_alert, env->NewStringUTF(caption),
|
|
|
|
env->NewStringUTF(text), yes_no ? JNI_TRUE : JNI_FALSE);
|
2015-06-08 00:13:52 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
// Must be called before the current thread exits; might as well do it here.
|
|
|
|
g_java_vm->DetachCurrentThread();
|
2015-06-08 00:13:52 +00:00
|
|
|
|
2018-01-07 22:30:28 +00:00
|
|
|
return result != JNI_FALSE;
|
2015-02-13 00:41:52 +00:00
|
|
|
}
|
|
|
|
|
2013-04-23 19:21:48 +00:00
|
|
|
#define DVD_BANNER_WIDTH 96
|
|
|
|
#define DVD_BANNER_HEIGHT 32
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
static inline u32 Average32(u32 a, u32 b)
|
|
|
|
{
|
|
|
|
return ((a >> 1) & 0x7f7f7f7f) + ((b >> 1) & 0x7f7f7f7f);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline u32 GetPixel(u32* buffer, unsigned int x, unsigned int y)
|
|
|
|
{
|
|
|
|
// thanks to unsignedness, these also check for <0 automatically.
|
|
|
|
if (x > 191)
|
|
|
|
return 0;
|
|
|
|
if (y > 63)
|
|
|
|
return 0;
|
|
|
|
return buffer[y * 192 + x];
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool LoadBanner(std::string filename, u32* Banner)
|
|
|
|
{
|
2017-06-06 09:49:01 +00:00
|
|
|
std::unique_ptr<DiscIO::Volume> pVolume(DiscIO::CreateVolumeFromFilename(filename));
|
2016-06-24 08:43:46 +00:00
|
|
|
|
|
|
|
if (pVolume != nullptr)
|
|
|
|
{
|
|
|
|
int Width, Height;
|
|
|
|
std::vector<u32> BannerVec = pVolume->GetBanner(&Width, &Height);
|
|
|
|
// This code (along with above inlines) is moved from
|
|
|
|
// elsewhere. Someone who knows anything about Android
|
|
|
|
// please get rid of it and use proper high-resolution
|
|
|
|
// images.
|
|
|
|
if (Height == 64 && Width == 192)
|
|
|
|
{
|
|
|
|
u32* Buffer = &BannerVec[0];
|
|
|
|
for (int y = 0; y < 32; y++)
|
|
|
|
{
|
|
|
|
for (int x = 0; x < 96; x++)
|
|
|
|
{
|
|
|
|
// simplified plus-shaped "gaussian"
|
|
|
|
u32 surround = Average32(
|
|
|
|
Average32(GetPixel(Buffer, x * 2 - 1, y * 2), GetPixel(Buffer, x * 2 + 1, y * 2)),
|
|
|
|
Average32(GetPixel(Buffer, x * 2, y * 2 - 1), GetPixel(Buffer, x * 2, y * 2 + 1)));
|
|
|
|
Banner[y * 96 + x] = Average32(GetPixel(Buffer, x * 2, y * 2), surround);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (Height == 32 && Width == 96)
|
|
|
|
{
|
|
|
|
memcpy(Banner, &BannerVec[0], 96 * 32 * 4);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2013-04-23 19:21:48 +00:00
|
|
|
}
|
2014-09-21 23:51:27 +00:00
|
|
|
|
2015-05-17 00:52:55 +00:00
|
|
|
static int GetCountry(std::string filename)
|
2015-05-07 00:12:58 +00:00
|
|
|
{
|
2017-06-06 09:49:01 +00:00
|
|
|
std::unique_ptr<DiscIO::Volume> pVolume(DiscIO::CreateVolumeFromFilename(filename));
|
2015-05-07 00:12:58 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
if (pVolume != nullptr)
|
|
|
|
{
|
2016-07-06 18:33:05 +00:00
|
|
|
int country = static_cast<int>(pVolume->GetCountry());
|
2015-05-07 00:12:58 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
__android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Country Code: %i", country);
|
2015-05-07 00:12:58 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
return country;
|
|
|
|
}
|
2015-05-07 00:12:58 +00:00
|
|
|
|
2016-07-06 18:33:05 +00:00
|
|
|
return static_cast<int>(DiscIO::Country::COUNTRY_UNKNOWN);
|
2015-05-07 00:12:58 +00:00
|
|
|
}
|
|
|
|
|
2015-05-17 00:52:55 +00:00
|
|
|
static int GetPlatform(std::string filename)
|
2015-05-16 23:02:46 +00:00
|
|
|
{
|
2017-06-06 09:49:01 +00:00
|
|
|
std::unique_ptr<DiscIO::Volume> pVolume(DiscIO::CreateVolumeFromFilename(filename));
|
2015-05-16 23:02:46 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
if (pVolume != nullptr)
|
|
|
|
{
|
|
|
|
switch (pVolume->GetVolumeType())
|
|
|
|
{
|
2016-07-06 18:33:05 +00:00
|
|
|
case DiscIO::Platform::GAMECUBE_DISC:
|
2016-06-24 08:43:46 +00:00
|
|
|
__android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Volume is a GameCube disc.");
|
|
|
|
return 0;
|
2016-07-06 18:33:05 +00:00
|
|
|
case DiscIO::Platform::WII_DISC:
|
2016-06-24 08:43:46 +00:00
|
|
|
__android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Volume is a Wii disc.");
|
|
|
|
return 1;
|
2016-07-06 18:33:05 +00:00
|
|
|
case DiscIO::Platform::WII_WAD:
|
2016-06-24 08:43:46 +00:00
|
|
|
__android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Volume is a Wii WAD.");
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
}
|
2015-05-16 23:02:46 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
return -1;
|
2015-05-16 23:02:46 +00:00
|
|
|
}
|
|
|
|
|
2015-05-07 00:12:58 +00:00
|
|
|
static std::string GetTitle(std::string filename)
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
__android_log_print(ANDROID_LOG_WARN, DOLPHIN_TAG, "Getting Title for file: %s",
|
|
|
|
filename.c_str());
|
2015-05-07 00:12:58 +00:00
|
|
|
|
2017-06-06 09:49:01 +00:00
|
|
|
std::unique_ptr<DiscIO::Volume> pVolume(DiscIO::CreateVolumeFromFilename(filename));
|
2015-05-07 00:12:58 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
if (pVolume != nullptr)
|
|
|
|
{
|
2016-07-06 18:33:05 +00:00
|
|
|
std::map<DiscIO::Language, std::string> titles = pVolume->GetLongNames();
|
2016-02-29 08:52:15 +00:00
|
|
|
if (titles.empty())
|
|
|
|
titles = pVolume->GetShortNames();
|
2015-05-07 00:12:58 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
/*
|
2016-07-06 18:33:05 +00:00
|
|
|
bool is_wii_title = pVolume->GetVolumeType() != DiscIO::Platform::GAMECUBE_DISC;
|
|
|
|
DiscIO::Language language = SConfig::GetInstance().GetCurrentLanguage(is_wii_title);
|
2015-05-07 00:12:58 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
auto it = titles.find(language);
|
|
|
|
if (it != end)
|
|
|
|
return it->second;*/
|
2015-05-07 00:12:58 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
auto end = titles.end();
|
2015-05-07 00:12:58 +00:00
|
|
|
|
2016-06-25 16:07:10 +00:00
|
|
|
// English tends to be a good fallback when the requested language isn't available
|
2016-07-06 18:33:05 +00:00
|
|
|
// if (language != DiscIO::Language::LANGUAGE_ENGLISH) {
|
|
|
|
auto it = titles.find(DiscIO::Language::LANGUAGE_ENGLISH);
|
2016-06-24 08:43:46 +00:00
|
|
|
if (it != end)
|
|
|
|
return it->second;
|
|
|
|
//}
|
2015-05-07 00:12:58 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
// If English isn't available either, just pick something
|
|
|
|
if (!titles.empty())
|
|
|
|
return titles.cbegin()->second;
|
2015-05-07 00:12:58 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
// No usable name, return filename (better than nothing)
|
|
|
|
std::string name;
|
|
|
|
SplitPath(filename, nullptr, &name, nullptr);
|
|
|
|
return name;
|
|
|
|
}
|
2015-05-07 00:12:58 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
return std::string("");
|
2015-05-07 00:12:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static std::string GetDescription(std::string filename)
|
2013-04-23 19:21:48 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
__android_log_print(ANDROID_LOG_WARN, DOLPHIN_TAG, "Getting Description for file: %s",
|
|
|
|
filename.c_str());
|
2015-04-10 20:10:49 +00:00
|
|
|
|
2017-06-06 09:49:01 +00:00
|
|
|
std::unique_ptr<DiscIO::Volume> volume(DiscIO::CreateVolumeFromFilename(filename));
|
2015-04-10 20:10:49 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
if (volume != nullptr)
|
|
|
|
{
|
2016-07-06 18:33:05 +00:00
|
|
|
std::map<DiscIO::Language, std::string> descriptions = volume->GetDescriptions();
|
2015-05-07 00:12:58 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
/*
|
2016-07-06 18:33:05 +00:00
|
|
|
bool is_wii_title = pVolume->GetVolumeType() != DiscIO::Platform::GAMECUBE_DISC;
|
|
|
|
DiscIO::Language language = SConfig::GetInstance().GetCurrentLanguage(is_wii_title);
|
2015-05-07 00:12:58 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
auto it = descriptions.find(language);
|
|
|
|
if (it != end)
|
|
|
|
return it->second;*/
|
2015-05-07 00:12:58 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
auto end = descriptions.end();
|
2015-05-07 00:12:58 +00:00
|
|
|
|
2016-06-25 16:07:10 +00:00
|
|
|
// English tends to be a good fallback when the requested language isn't available
|
2016-07-06 18:33:05 +00:00
|
|
|
// if (language != DiscIO::Language::LANGUAGE_ENGLISH) {
|
|
|
|
auto it = descriptions.find(DiscIO::Language::LANGUAGE_ENGLISH);
|
2016-06-24 08:43:46 +00:00
|
|
|
if (it != end)
|
|
|
|
return it->second;
|
|
|
|
//}
|
2015-05-07 00:12:58 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
// If English isn't available either, just pick something
|
|
|
|
if (!descriptions.empty())
|
|
|
|
return descriptions.cbegin()->second;
|
|
|
|
}
|
2015-04-10 20:10:49 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
return std::string();
|
2015-05-07 00:12:58 +00:00
|
|
|
}
|
2013-04-23 19:21:48 +00:00
|
|
|
|
2015-05-07 00:12:58 +00:00
|
|
|
static std::string GetGameId(std::string filename)
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
__android_log_print(ANDROID_LOG_WARN, DOLPHIN_TAG, "Getting ID for file: %s", filename.c_str());
|
2015-05-07 00:12:58 +00:00
|
|
|
|
2017-06-06 09:49:01 +00:00
|
|
|
std::unique_ptr<DiscIO::Volume> volume(DiscIO::CreateVolumeFromFilename(filename));
|
2016-06-24 08:43:46 +00:00
|
|
|
if (volume == nullptr)
|
|
|
|
return std::string();
|
2015-05-07 00:12:58 +00:00
|
|
|
|
2016-10-29 12:42:43 +00:00
|
|
|
std::string id = volume->GetGameID();
|
2016-06-24 08:43:46 +00:00
|
|
|
__android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Game ID: %s", id.c_str());
|
|
|
|
return id;
|
2015-05-07 00:12:58 +00:00
|
|
|
}
|
|
|
|
|
2015-05-17 00:52:55 +00:00
|
|
|
static std::string GetCompany(std::string filename)
|
2015-05-07 00:12:58 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
__android_log_print(ANDROID_LOG_WARN, DOLPHIN_TAG, "Getting Company for file: %s",
|
|
|
|
filename.c_str());
|
2015-05-07 00:12:58 +00:00
|
|
|
|
2017-06-06 09:49:01 +00:00
|
|
|
std::unique_ptr<DiscIO::Volume> volume(DiscIO::CreateVolumeFromFilename(filename));
|
2016-06-24 08:43:46 +00:00
|
|
|
if (volume == nullptr)
|
|
|
|
return std::string();
|
2015-12-07 04:15:51 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
std::string company = DiscIO::GetCompanyFromID(volume->GetMakerID());
|
|
|
|
__android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Company: %s", company.c_str());
|
|
|
|
return company;
|
2015-05-07 00:12:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static u64 GetFileSize(std::string filename)
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
__android_log_print(ANDROID_LOG_WARN, DOLPHIN_TAG, "Getting size of file: %s", filename.c_str());
|
2015-05-07 00:12:58 +00:00
|
|
|
|
2017-06-06 09:49:01 +00:00
|
|
|
std::unique_ptr<DiscIO::Volume> volume(DiscIO::CreateVolumeFromFilename(filename));
|
2016-06-24 08:43:46 +00:00
|
|
|
if (volume == nullptr)
|
|
|
|
return -1;
|
2015-05-07 00:12:58 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
u64 size = volume->GetSize();
|
|
|
|
__android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Size: %" PRIu64, size);
|
|
|
|
return size;
|
2013-04-23 19:21:48 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
static std::string GetJString(JNIEnv* env, jstring jstr)
|
2014-03-14 21:20:44 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
std::string result = "";
|
|
|
|
if (!jstr)
|
|
|
|
return result;
|
2014-03-29 10:05:44 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
const char* s = env->GetStringUTFChars(jstr, nullptr);
|
|
|
|
result = s;
|
|
|
|
env->ReleaseStringUTFChars(jstr, s);
|
|
|
|
return result;
|
2014-03-14 21:20:44 +00:00
|
|
|
}
|
2013-04-23 19:21:48 +00:00
|
|
|
|
2013-02-26 19:49:00 +00:00
|
|
|
#ifdef __cplusplus
|
2016-06-24 08:43:46 +00:00
|
|
|
extern "C" {
|
2013-02-26 19:49:00 +00:00
|
|
|
#endif
|
2014-03-14 21:20:44 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_UnPauseEmulation(JNIEnv* env,
|
|
|
|
jobject obj);
|
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_PauseEmulation(JNIEnv* env,
|
|
|
|
jobject obj);
|
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_StopEmulation(JNIEnv* env,
|
|
|
|
jobject obj);
|
2017-12-25 12:57:31 +00:00
|
|
|
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_IsRunning(JNIEnv* env,
|
|
|
|
jobject obj);
|
2016-06-24 08:43:46 +00:00
|
|
|
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_onGamePadEvent(
|
|
|
|
JNIEnv* env, jobject obj, jstring jDevice, jint Button, jint Action);
|
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_onGamePadMoveEvent(
|
|
|
|
JNIEnv* env, jobject obj, jstring jDevice, jint Axis, jfloat Value);
|
|
|
|
JNIEXPORT jintArray JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetBanner(JNIEnv* env,
|
|
|
|
jobject obj,
|
|
|
|
jstring jFile);
|
|
|
|
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetTitle(JNIEnv* env,
|
|
|
|
jobject obj,
|
|
|
|
jstring jFilename);
|
|
|
|
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetDescription(
|
|
|
|
JNIEnv* env, jobject obj, jstring jFilename);
|
|
|
|
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetGameId(JNIEnv* env,
|
|
|
|
jobject obj,
|
|
|
|
jstring jFilename);
|
|
|
|
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetCountry(JNIEnv* env,
|
|
|
|
jobject obj,
|
|
|
|
jstring jFilename);
|
|
|
|
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetCompany(
|
|
|
|
JNIEnv* env, jobject obj, jstring jFilename);
|
|
|
|
JNIEXPORT jlong JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetFilesize(JNIEnv* env,
|
|
|
|
jobject obj,
|
|
|
|
jstring jFilename);
|
|
|
|
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetPlatform(JNIEnv* env,
|
|
|
|
jobject obj,
|
|
|
|
jstring jFilename);
|
|
|
|
JNIEXPORT jstring JNICALL
|
|
|
|
Java_org_dolphinemu_dolphinemu_NativeLibrary_GetVersionString(JNIEnv* env, jobject obj);
|
2017-09-10 06:43:12 +00:00
|
|
|
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetGitRevision(JNIEnv* env,
|
|
|
|
jobject obj);
|
2016-06-24 08:43:46 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SaveScreenShot(JNIEnv* env,
|
|
|
|
jobject obj);
|
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_eglBindAPI(JNIEnv* env,
|
|
|
|
jobject obj,
|
|
|
|
jint api);
|
|
|
|
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetConfig(
|
|
|
|
JNIEnv* env, jobject obj, jstring jFile, jstring jSection, jstring jKey, jstring jDefault);
|
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetConfig(
|
|
|
|
JNIEnv* env, jobject obj, jstring jFile, jstring jSection, jstring jKey, jstring jValue);
|
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetFilename(JNIEnv* env,
|
|
|
|
jobject obj,
|
|
|
|
jstring jFile);
|
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SaveState(JNIEnv* env,
|
|
|
|
jobject obj,
|
2017-12-26 21:22:42 +00:00
|
|
|
jint slot,
|
|
|
|
jboolean wait);
|
2017-12-25 12:50:29 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SaveStateAs(JNIEnv* env,
|
|
|
|
jobject obj,
|
2017-12-26 21:22:42 +00:00
|
|
|
jstring path,
|
|
|
|
jboolean wait);
|
2016-06-24 08:43:46 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_LoadState(JNIEnv* env,
|
|
|
|
jobject obj,
|
|
|
|
jint slot);
|
2017-12-25 12:50:29 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_LoadStateAs(JNIEnv* env,
|
|
|
|
jobject obj,
|
|
|
|
jstring path);
|
2017-09-09 09:27:24 +00:00
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
Java_org_dolphinemu_dolphinemu_services_DirectoryInitializationService_CreateUserDirectories(
|
|
|
|
JNIEnv* env, jobject obj);
|
2016-06-24 08:43:46 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetUserDirectory(
|
|
|
|
JNIEnv* env, jobject obj, jstring jDirectory);
|
|
|
|
JNIEXPORT jstring JNICALL
|
|
|
|
Java_org_dolphinemu_dolphinemu_NativeLibrary_GetUserDirectory(JNIEnv* env, jobject obj);
|
2017-06-05 00:29:56 +00:00
|
|
|
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_DefaultCPUCore(JNIEnv* env,
|
|
|
|
jobject obj);
|
2016-06-24 08:43:46 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetProfiling(JNIEnv* env,
|
|
|
|
jobject obj,
|
|
|
|
jboolean enable);
|
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
Java_org_dolphinemu_dolphinemu_NativeLibrary_WriteProfileResults(JNIEnv* env, jobject obj);
|
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
Java_org_dolphinemu_dolphinemu_NativeLibrary_CacheClassesAndMethods(JNIEnv* env, jobject obj);
|
2017-12-26 21:08:44 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Run__Ljava_lang_String_2(
|
|
|
|
JNIEnv* env, jobject obj, jstring jFile);
|
|
|
|
JNIEXPORT void JNICALL
|
2017-12-28 09:13:53 +00:00
|
|
|
Java_org_dolphinemu_dolphinemu_NativeLibrary_Run__Ljava_lang_String_2Ljava_lang_String_2Z(
|
|
|
|
JNIEnv* env, jobject obj, jstring jFile, jstring jSavestate, jboolean jDeleteSavestate);
|
2016-06-24 08:43:46 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SurfaceChanged(JNIEnv* env,
|
|
|
|
jobject obj,
|
2017-05-18 23:33:44 +00:00
|
|
|
jobject surf);
|
2016-06-24 08:43:46 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SurfaceDestroyed(JNIEnv* env,
|
|
|
|
jobject obj);
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_UnPauseEmulation(JNIEnv* env,
|
|
|
|
jobject obj)
|
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> guard(s_host_identity_lock);
|
2017-02-05 12:39:58 +00:00
|
|
|
Core::SetState(Core::State::Running);
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_PauseEmulation(JNIEnv* env,
|
|
|
|
jobject obj)
|
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> guard(s_host_identity_lock);
|
2017-02-05 12:39:58 +00:00
|
|
|
Core::SetState(Core::State::Paused);
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_StopEmulation(JNIEnv* env,
|
|
|
|
jobject obj)
|
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> guard(s_host_identity_lock);
|
2017-03-04 06:42:35 +00:00
|
|
|
Core::SaveScreenShot("thumb", true);
|
2016-06-24 08:43:46 +00:00
|
|
|
Core::Stop();
|
2017-05-18 23:33:44 +00:00
|
|
|
s_update_main_frame_event.Set(); // Kick the waiting event
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
2017-12-25 12:57:31 +00:00
|
|
|
|
|
|
|
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_IsRunning(JNIEnv* env,
|
|
|
|
jobject obj)
|
|
|
|
{
|
|
|
|
return Core::IsRunning();
|
|
|
|
}
|
|
|
|
|
2018-01-21 00:31:53 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_ChangeDisc(JNIEnv* env,
|
|
|
|
jobject obj,
|
|
|
|
jstring jFile);
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_onGamePadEvent(
|
|
|
|
JNIEnv* env, jobject obj, jstring jDevice, jint Button, jint Action)
|
|
|
|
{
|
|
|
|
return ButtonManager::GamepadEvent(GetJString(env, jDevice), Button, Action);
|
|
|
|
}
|
2017-12-25 12:57:31 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_onGamePadMoveEvent(
|
|
|
|
JNIEnv* env, jobject obj, jstring jDevice, jint Axis, jfloat Value)
|
|
|
|
{
|
|
|
|
ButtonManager::GamepadAxisEvent(GetJString(env, jDevice), Axis, Value);
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jintArray JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetBanner(JNIEnv* env,
|
|
|
|
jobject obj,
|
|
|
|
jstring jFile)
|
2013-03-20 02:53:09 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
std::string file = GetJString(env, jFile);
|
|
|
|
u32 uBanner[DVD_BANNER_WIDTH * DVD_BANNER_HEIGHT];
|
|
|
|
jintArray Banner = env->NewIntArray(DVD_BANNER_WIDTH * DVD_BANNER_HEIGHT);
|
2013-03-20 02:53:09 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
if (LoadBanner(file, uBanner))
|
|
|
|
{
|
|
|
|
env->SetIntArrayRegion(Banner, 0, DVD_BANNER_WIDTH * DVD_BANNER_HEIGHT, (jint*)uBanner);
|
|
|
|
}
|
|
|
|
return Banner;
|
2013-04-23 19:21:48 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetTitle(JNIEnv* env,
|
|
|
|
jobject obj,
|
|
|
|
jstring jFilename)
|
2015-05-07 00:12:58 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
std::string filename = GetJString(env, jFilename);
|
|
|
|
std::string name = GetTitle(filename);
|
|
|
|
return env->NewStringUTF(name.c_str());
|
2013-04-23 19:21:48 +00:00
|
|
|
}
|
2013-11-15 23:32:50 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetDescription(
|
|
|
|
JNIEnv* env, jobject obj, jstring jFilename)
|
2015-05-07 00:12:58 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
std::string filename = GetJString(env, jFilename);
|
|
|
|
std::string description = GetDescription(filename);
|
|
|
|
return env->NewStringUTF(description.c_str());
|
2015-05-07 00:12:58 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetGameId(JNIEnv* env,
|
|
|
|
jobject obj,
|
|
|
|
jstring jFilename)
|
2015-05-07 00:12:58 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
std::string filename = GetJString(env, jFilename);
|
|
|
|
std::string id = GetGameId(filename);
|
|
|
|
return env->NewStringUTF(id.c_str());
|
2015-05-07 00:12:58 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetCompany(JNIEnv* env,
|
|
|
|
jobject obj,
|
|
|
|
jstring jFilename)
|
2015-05-07 00:12:58 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
std::string filename = GetJString(env, jFilename);
|
|
|
|
std::string company = GetCompany(filename);
|
|
|
|
return env->NewStringUTF(company.c_str());
|
2015-05-07 00:12:58 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetCountry(JNIEnv* env,
|
|
|
|
jobject obj,
|
|
|
|
jstring jFilename)
|
2015-05-16 23:02:46 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
std::string filename = GetJString(env, jFilename);
|
|
|
|
int country = GetCountry(filename);
|
|
|
|
return country;
|
2015-05-16 23:02:46 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
JNIEXPORT jlong JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetFilesize(JNIEnv* env,
|
|
|
|
jobject obj,
|
|
|
|
jstring jFilename)
|
2015-05-07 00:12:58 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
std::string filename = GetJString(env, jFilename);
|
|
|
|
u64 size = GetFileSize(filename);
|
|
|
|
return size;
|
2015-05-07 00:12:58 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetPlatform(JNIEnv* env,
|
|
|
|
jobject obj,
|
|
|
|
jstring jFilename)
|
2015-05-07 00:12:58 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
std::string filename = GetJString(env, jFilename);
|
|
|
|
int platform = GetPlatform(filename);
|
|
|
|
return platform;
|
2015-05-07 00:12:58 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetVersionString(JNIEnv* env,
|
|
|
|
jobject obj)
|
2013-06-23 03:54:28 +00:00
|
|
|
{
|
2017-09-09 19:52:35 +00:00
|
|
|
return env->NewStringUTF(Common::scm_rev_str.c_str());
|
2013-06-23 03:54:28 +00:00
|
|
|
}
|
2013-11-15 20:17:47 +00:00
|
|
|
|
2017-09-10 06:43:12 +00:00
|
|
|
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetGitRevision(JNIEnv* env,
|
|
|
|
jobject obj)
|
|
|
|
{
|
|
|
|
return env->NewStringUTF(Common::scm_rev_git_str.c_str());
|
|
|
|
}
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SaveScreenShot(JNIEnv* env,
|
|
|
|
jobject obj)
|
2013-11-15 23:32:50 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
std::lock_guard<std::mutex> guard(s_host_identity_lock);
|
|
|
|
Core::SaveScreenShot();
|
2013-11-15 23:32:50 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_eglBindAPI(JNIEnv* env,
|
|
|
|
jobject obj,
|
|
|
|
jint api)
|
2014-02-11 06:16:21 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
eglBindAPI(api);
|
2014-02-11 06:16:21 +00:00
|
|
|
}
|
|
|
|
|
2018-02-16 18:47:52 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_InitGameIni(JNIEnv* env,
|
|
|
|
jobject obj,
|
|
|
|
jstring jGameID)
|
|
|
|
{
|
|
|
|
// Initialize an empty INI file
|
|
|
|
IniFile ini;
|
|
|
|
std::string gameid = GetJString(env, jGameID);
|
|
|
|
|
|
|
|
__android_log_print(ANDROID_LOG_DEBUG, "InitGameIni", "Initializing base game config file");
|
|
|
|
ini.Save(File::GetUserPath(D_GAMESETTINGS_IDX) + gameid + ".ini");
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetUserSetting(
|
|
|
|
JNIEnv* env, jobject obj, jstring jGameID, jstring jSection, jstring jKey)
|
|
|
|
{
|
|
|
|
IniFile ini;
|
|
|
|
std::string gameid = GetJString(env, jGameID);
|
|
|
|
std::string section = GetJString(env, jSection);
|
|
|
|
std::string key = GetJString(env, jKey);
|
|
|
|
|
|
|
|
ini = SConfig::GetInstance().LoadGameIni(gameid, 0);
|
|
|
|
std::string value;
|
|
|
|
|
|
|
|
ini.GetOrCreateSection(section)->Get(key, &value, "-1");
|
|
|
|
|
|
|
|
return env->NewStringUTF(value.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetUserSetting(
|
|
|
|
JNIEnv* env, jobject obj, jstring jGameID, jstring jSection, jstring jKey, jstring jValue)
|
|
|
|
{
|
|
|
|
IniFile ini;
|
|
|
|
std::string gameid = GetJString(env, jGameID);
|
|
|
|
std::string section = GetJString(env, jSection);
|
|
|
|
std::string key = GetJString(env, jKey);
|
|
|
|
std::string val = GetJString(env, jValue);
|
|
|
|
|
|
|
|
ini.Load(File::GetUserPath(D_GAMESETTINGS_IDX) + gameid + ".ini");
|
|
|
|
|
|
|
|
if (val != "-1")
|
|
|
|
{
|
|
|
|
ini.GetOrCreateSection(section)->Set(key, val);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ini.GetOrCreateSection(section)->Delete(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
ini.Save(File::GetUserPath(D_GAMESETTINGS_IDX) + gameid + ".ini");
|
|
|
|
}
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetConfig(
|
|
|
|
JNIEnv* env, jobject obj, jstring jFile, jstring jSection, jstring jKey, jstring jDefault)
|
2013-04-23 19:21:48 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
IniFile ini;
|
|
|
|
std::string file = GetJString(env, jFile);
|
|
|
|
std::string section = GetJString(env, jSection);
|
|
|
|
std::string key = GetJString(env, jKey);
|
|
|
|
std::string defaultValue = GetJString(env, jDefault);
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
ini.Load(File::GetUserPath(D_CONFIG_IDX) + std::string(file));
|
|
|
|
std::string value;
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
ini.GetOrCreateSection(section)->Get(key, &value, defaultValue);
|
2013-04-23 19:21:48 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
return env->NewStringUTF(value.c_str());
|
2013-04-23 19:21:48 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetConfig(
|
|
|
|
JNIEnv* env, jobject obj, jstring jFile, jstring jSection, jstring jKey, jstring jValue)
|
2013-04-23 19:21:48 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
IniFile ini;
|
|
|
|
std::string file = GetJString(env, jFile);
|
|
|
|
std::string section = GetJString(env, jSection);
|
|
|
|
std::string key = GetJString(env, jKey);
|
|
|
|
std::string value = GetJString(env, jValue);
|
2013-06-18 12:09:20 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
ini.Load(File::GetUserPath(D_CONFIG_IDX) + std::string(file));
|
2013-04-23 19:21:48 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
ini.GetOrCreateSection(section)->Set(key, value);
|
|
|
|
ini.Save(File::GetUserPath(D_CONFIG_IDX) + std::string(file));
|
2013-04-23 19:21:48 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SaveState(JNIEnv* env,
|
|
|
|
jobject obj,
|
2017-12-26 21:22:42 +00:00
|
|
|
jint slot,
|
|
|
|
jboolean wait)
|
2013-08-29 22:47:50 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
std::lock_guard<std::mutex> guard(s_host_identity_lock);
|
2017-12-26 21:22:42 +00:00
|
|
|
State::Save(slot, wait);
|
2013-08-29 22:47:50 +00:00
|
|
|
}
|
|
|
|
|
2017-12-25 12:50:29 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SaveStateAs(JNIEnv* env,
|
|
|
|
jobject obj,
|
2017-12-26 21:22:42 +00:00
|
|
|
jstring path,
|
|
|
|
jboolean wait)
|
2017-12-25 12:50:29 +00:00
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> guard(s_host_identity_lock);
|
2017-12-26 21:22:42 +00:00
|
|
|
State::SaveAs(GetJString(env, path), wait);
|
2013-08-29 22:47:50 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_LoadState(JNIEnv* env,
|
|
|
|
jobject obj,
|
|
|
|
jint slot)
|
2013-08-29 22:47:50 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
std::lock_guard<std::mutex> guard(s_host_identity_lock);
|
|
|
|
State::Load(slot);
|
2013-08-29 22:47:50 +00:00
|
|
|
}
|
|
|
|
|
2017-12-25 12:50:29 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_LoadStateAs(JNIEnv* env,
|
|
|
|
jobject obj,
|
|
|
|
jstring path)
|
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> guard(s_host_identity_lock);
|
|
|
|
State::LoadAs(GetJString(env, path));
|
|
|
|
}
|
|
|
|
|
2017-09-09 09:27:24 +00:00
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
Java_org_dolphinemu_dolphinemu_services_DirectoryInitializationService_SetSysDirectory(
|
|
|
|
JNIEnv* env, jobject obj, jstring jPath)
|
|
|
|
{
|
|
|
|
const std::string path = GetJString(env, jPath);
|
|
|
|
File::SetSysDirectory(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
Java_org_dolphinemu_dolphinemu_services_DirectoryInitializationService_CreateUserDirectories(
|
|
|
|
JNIEnv* env, jobject obj)
|
|
|
|
{
|
|
|
|
UICommon::CreateDirectories();
|
2013-08-29 23:07:32 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetUserDirectory(
|
|
|
|
JNIEnv* env, jobject obj, jstring jDirectory)
|
2015-02-25 09:23:42 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
std::lock_guard<std::mutex> guard(s_host_identity_lock);
|
2017-12-28 12:34:49 +00:00
|
|
|
UICommon::SetUserDirectory(GetJString(env, jDirectory));
|
2015-02-25 09:23:42 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetUserDirectory(JNIEnv* env,
|
|
|
|
jobject obj)
|
2015-02-28 05:20:33 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
return env->NewStringUTF(File::GetUserPath(D_USER_IDX).c_str());
|
2015-02-28 05:20:33 +00:00
|
|
|
}
|
|
|
|
|
2017-04-15 14:23:48 +00:00
|
|
|
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_DefaultCPUCore(JNIEnv* env,
|
|
|
|
jobject obj)
|
|
|
|
{
|
|
|
|
return PowerPC::DefaultCPUCore();
|
|
|
|
}
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetProfiling(JNIEnv* env,
|
|
|
|
jobject obj,
|
|
|
|
jboolean enable)
|
2015-05-11 01:03:34 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
std::lock_guard<std::mutex> guard(s_host_identity_lock);
|
2017-02-05 12:39:58 +00:00
|
|
|
Core::SetState(Core::State::Paused);
|
2016-06-24 08:43:46 +00:00
|
|
|
JitInterface::ClearCache();
|
|
|
|
Profiler::g_ProfileBlocks = enable;
|
2017-02-05 12:39:58 +00:00
|
|
|
Core::SetState(Core::State::Running);
|
2015-05-11 01:03:34 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_WriteProfileResults(JNIEnv* env,
|
|
|
|
jobject obj)
|
2015-05-11 01:03:34 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
std::lock_guard<std::mutex> guard(s_host_identity_lock);
|
|
|
|
std::string filename = File::GetUserPath(D_DUMP_IDX) + "Debug/profiler.txt";
|
|
|
|
File::CreateFullPath(filename);
|
|
|
|
JitInterface::WriteProfileResults(filename);
|
2015-05-11 01:03:34 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
Java_org_dolphinemu_dolphinemu_NativeLibrary_CacheClassesAndMethods(JNIEnv* env, jobject obj)
|
2015-06-08 00:13:52 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
// This class reference is only valid for the lifetime of this method.
|
|
|
|
jclass localClass = env->FindClass("org/dolphinemu/dolphinemu/NativeLibrary");
|
2015-06-08 00:13:52 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
// This reference, however, is valid until we delete it.
|
2017-05-18 23:33:44 +00:00
|
|
|
s_jni_class = reinterpret_cast<jclass>(env->NewGlobalRef(localClass));
|
2015-06-08 00:13:52 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
// TODO Find a place for this.
|
|
|
|
// So we don't leak a reference to NativeLibrary.class.
|
2017-05-18 23:33:44 +00:00
|
|
|
// env->DeleteGlobalRef(s_jni_class);
|
2015-06-08 00:13:52 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
// Method signature taken from javap -s
|
|
|
|
// Source/Android/app/build/intermediates/classes/arm/debug/org/dolphinemu/dolphinemu/NativeLibrary.class
|
2018-01-07 22:30:28 +00:00
|
|
|
s_jni_method_alert = env->GetStaticMethodID(s_jni_class, "displayAlertMsg",
|
|
|
|
"(Ljava/lang/String;Ljava/lang/String;Z)Z");
|
2015-06-08 00:13:52 +00:00
|
|
|
}
|
|
|
|
|
2016-01-10 18:31:49 +00:00
|
|
|
// Surface Handling
|
2016-06-24 08:43:46 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SurfaceChanged(JNIEnv* env,
|
|
|
|
jobject obj,
|
2017-05-18 23:33:44 +00:00
|
|
|
jobject surf)
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2017-05-18 23:33:44 +00:00
|
|
|
s_surf = ANativeWindow_fromSurface(env, surf);
|
|
|
|
if (s_surf == nullptr)
|
2016-06-24 08:43:46 +00:00
|
|
|
__android_log_print(ANDROID_LOG_ERROR, DOLPHIN_TAG, "Error: Surface is null.");
|
|
|
|
|
2016-08-13 12:08:53 +00:00
|
|
|
if (g_renderer)
|
2017-05-18 23:33:44 +00:00
|
|
|
g_renderer->ChangeSurface(s_surf);
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SurfaceDestroyed(JNIEnv* env,
|
|
|
|
jobject obj)
|
|
|
|
{
|
2016-08-13 12:08:53 +00:00
|
|
|
if (g_renderer)
|
|
|
|
g_renderer->ChangeSurface(nullptr);
|
|
|
|
|
2017-05-18 23:33:44 +00:00
|
|
|
if (s_surf)
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2017-05-18 23:33:44 +00:00
|
|
|
ANativeWindow_release(s_surf);
|
|
|
|
s_surf = nullptr;
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_RefreshWiimotes(JNIEnv* env,
|
|
|
|
jobject obj)
|
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> guard(s_host_identity_lock);
|
|
|
|
WiimoteReal::Refresh();
|
|
|
|
}
|
|
|
|
|
2017-12-28 09:13:53 +00:00
|
|
|
static void Run(const std::string& path, std::optional<std::string> savestate_path = {},
|
|
|
|
bool delete_savestate = false)
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2017-08-23 20:32:23 +00:00
|
|
|
__android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Running : %s", path.c_str());
|
2016-06-24 08:43:46 +00:00
|
|
|
|
|
|
|
// Install our callbacks
|
|
|
|
OSD::AddCallback(OSD::CallbackType::Initialization, ButtonManager::Init);
|
|
|
|
OSD::AddCallback(OSD::CallbackType::Shutdown, ButtonManager::Shutdown);
|
|
|
|
|
|
|
|
RegisterMsgAlertHandler(&MsgAlert);
|
|
|
|
|
|
|
|
std::unique_lock<std::mutex> guard(s_host_identity_lock);
|
|
|
|
UICommon::Init();
|
|
|
|
|
|
|
|
WiimoteReal::InitAdapterClass();
|
|
|
|
|
|
|
|
// No use running the loop when booting fails
|
|
|
|
s_have_wm_user_stop = false;
|
2017-12-28 09:13:53 +00:00
|
|
|
std::unique_ptr<BootParameters> boot = BootParameters::GenerateFromFile(path, savestate_path);
|
|
|
|
boot->delete_savestate = delete_savestate;
|
|
|
|
if (BootManager::BootCore(std::move(boot)))
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
|
|
|
static constexpr int TIMEOUT = 10000;
|
|
|
|
static constexpr int WAIT_STEP = 25;
|
|
|
|
int time_waited = 0;
|
|
|
|
// A Core::CORE_ERROR state would be helpful here.
|
|
|
|
while (!Core::IsRunning() && time_waited < TIMEOUT && !s_have_wm_user_stop)
|
|
|
|
{
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_STEP));
|
|
|
|
time_waited += WAIT_STEP;
|
|
|
|
}
|
|
|
|
while (Core::IsRunning())
|
|
|
|
{
|
|
|
|
guard.unlock();
|
2017-05-18 23:33:44 +00:00
|
|
|
s_update_main_frame_event.Wait();
|
2016-06-24 08:43:46 +00:00
|
|
|
guard.lock();
|
|
|
|
Core::HostDispatchJobs();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Core::Shutdown();
|
|
|
|
UICommon::Shutdown();
|
|
|
|
guard.unlock();
|
|
|
|
|
2017-05-18 23:33:44 +00:00
|
|
|
if (s_surf)
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2017-05-18 23:33:44 +00:00
|
|
|
ANativeWindow_release(s_surf);
|
|
|
|
s_surf = nullptr;
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
2013-02-26 19:49:00 +00:00
|
|
|
}
|
2013-07-27 20:09:18 +00:00
|
|
|
|
2017-12-26 21:08:44 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Run__Ljava_lang_String_2(
|
|
|
|
JNIEnv* env, jobject obj, jstring jFile)
|
|
|
|
{
|
|
|
|
Run(GetJString(env, jFile));
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL
|
2017-12-28 09:13:53 +00:00
|
|
|
Java_org_dolphinemu_dolphinemu_NativeLibrary_Run__Ljava_lang_String_2Ljava_lang_String_2Z(
|
|
|
|
JNIEnv* env, jobject obj, jstring jFile, jstring jSavestate, jboolean jDeleteSavestate)
|
2017-12-26 21:08:44 +00:00
|
|
|
{
|
2017-12-28 09:13:53 +00:00
|
|
|
Run(GetJString(env, jFile), GetJString(env, jSavestate), jDeleteSavestate);
|
2017-12-26 21:08:44 +00:00
|
|
|
}
|
|
|
|
|
2018-01-21 00:31:53 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_ChangeDisc(JNIEnv* env,
|
|
|
|
jobject obj,
|
|
|
|
jstring jFile)
|
|
|
|
{
|
|
|
|
const std::string path = GetJString(env, jFile);
|
|
|
|
__android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Change Disc: %s", path.c_str());
|
|
|
|
Core::RunAsCPUThread([&path] { DVDInterface::ChangeDisc(path); });
|
|
|
|
}
|
|
|
|
|
2013-02-26 19:49:00 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|