2022-01-23 20:47:57 +00:00
|
|
|
// Copyright 2022 Dolphin Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
|
|
|
#include <jni.h>
|
|
|
|
|
2022-12-26 18:26:58 +00:00
|
|
|
#include "Common/FileUtil.h"
|
2022-08-14 11:05:30 +00:00
|
|
|
#include "Common/IniFile.h"
|
2022-01-23 20:47:57 +00:00
|
|
|
#include "Core/HW/GCPad.h"
|
|
|
|
#include "Core/HW/Wiimote.h"
|
|
|
|
#include "Core/HW/WiimoteEmu/WiimoteEmu.h"
|
|
|
|
#include "InputCommon/ControllerEmu/ControlGroup/Attachments.h"
|
|
|
|
#include "InputCommon/ControllerEmu/ControllerEmu.h"
|
|
|
|
#include "InputCommon/ControllerInterface/ControllerInterface.h"
|
|
|
|
#include "InputCommon/InputConfig.h"
|
|
|
|
#include "jni/AndroidCommon/AndroidCommon.h"
|
|
|
|
#include "jni/AndroidCommon/IDCache.h"
|
|
|
|
#include "jni/Input/Control.h"
|
|
|
|
#include "jni/Input/ControlGroup.h"
|
|
|
|
#include "jni/Input/ControlReference.h"
|
|
|
|
|
2022-08-14 09:32:22 +00:00
|
|
|
ControllerEmu::EmulatedController* EmulatedControllerFromJava(JNIEnv* env, jobject obj)
|
2022-01-23 20:47:57 +00:00
|
|
|
{
|
|
|
|
return reinterpret_cast<ControllerEmu::EmulatedController*>(
|
|
|
|
env->GetLongField(obj, IDCache::GetEmulatedControllerPointer()));
|
|
|
|
}
|
|
|
|
|
|
|
|
static jobject EmulatedControllerToJava(JNIEnv* env, ControllerEmu::EmulatedController* controller)
|
|
|
|
{
|
|
|
|
if (!controller)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return env->NewObject(IDCache::GetEmulatedControllerClass(),
|
|
|
|
IDCache::GetEmulatedControllerConstructor(),
|
|
|
|
reinterpret_cast<jlong>(controller));
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
|
2022-08-14 09:32:22 +00:00
|
|
|
JNIEXPORT jstring JNICALL
|
|
|
|
Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_EmulatedController_getDefaultDevice(
|
|
|
|
JNIEnv* env, jobject obj)
|
|
|
|
{
|
|
|
|
return ToJString(env, EmulatedControllerFromJava(env, obj)->GetDefaultDevice().ToString());
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_EmulatedController_setDefaultDevice(
|
|
|
|
JNIEnv* env, jobject obj, jstring j_device)
|
|
|
|
{
|
|
|
|
return EmulatedControllerFromJava(env, obj)->SetDefaultDevice(GetJString(env, j_device));
|
|
|
|
}
|
|
|
|
|
2022-01-23 20:47:57 +00:00
|
|
|
JNIEXPORT jint JNICALL
|
|
|
|
Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_EmulatedController_getGroupCount(
|
|
|
|
JNIEnv* env, jobject obj)
|
|
|
|
{
|
2022-08-14 09:32:22 +00:00
|
|
|
return static_cast<jint>(EmulatedControllerFromJava(env, obj)->groups.size());
|
2022-01-23 20:47:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jobject JNICALL
|
|
|
|
Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_EmulatedController_getGroup(
|
|
|
|
JNIEnv* env, jobject obj, jint controller_index)
|
|
|
|
{
|
2022-08-14 09:32:22 +00:00
|
|
|
return ControlGroupToJava(env,
|
|
|
|
EmulatedControllerFromJava(env, obj)->groups[controller_index].get());
|
2022-01-23 20:47:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_EmulatedController_updateSingleControlReference(
|
|
|
|
JNIEnv* env, jobject obj, jobject control_reference)
|
|
|
|
{
|
2022-08-14 09:32:22 +00:00
|
|
|
return EmulatedControllerFromJava(env, obj)->UpdateSingleControlReference(
|
2022-01-23 20:47:57 +00:00
|
|
|
g_controller_interface, ControlReferenceFromJava(env, control_reference));
|
|
|
|
}
|
|
|
|
|
2022-08-14 11:05:30 +00:00
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_EmulatedController_loadDefaultSettings(
|
|
|
|
JNIEnv* env, jobject obj)
|
|
|
|
{
|
|
|
|
ControllerEmu::EmulatedController* controller = EmulatedControllerFromJava(env, obj);
|
|
|
|
|
|
|
|
controller->LoadDefaults(g_controller_interface);
|
|
|
|
controller->UpdateReferences(g_controller_interface);
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_EmulatedController_clearSettings(
|
|
|
|
JNIEnv* env, jobject obj)
|
|
|
|
{
|
|
|
|
ControllerEmu::EmulatedController* controller = EmulatedControllerFromJava(env, obj);
|
|
|
|
|
|
|
|
// Loading an empty IniFile section clears everything.
|
|
|
|
IniFile::Section section;
|
|
|
|
|
|
|
|
controller->LoadConfig(§ion);
|
|
|
|
controller->UpdateReferences(g_controller_interface);
|
|
|
|
}
|
|
|
|
|
2022-12-26 18:26:58 +00:00
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_EmulatedController_loadProfile(
|
|
|
|
JNIEnv* env, jobject obj, jstring j_path)
|
|
|
|
{
|
|
|
|
ControllerEmu::EmulatedController* controller = EmulatedControllerFromJava(env, obj);
|
|
|
|
|
|
|
|
IniFile ini;
|
|
|
|
ini.Load(GetJString(env, j_path));
|
|
|
|
|
|
|
|
controller->LoadConfig(ini.GetOrCreateSection("Profile"));
|
|
|
|
controller->UpdateReferences(g_controller_interface);
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_EmulatedController_saveProfile(
|
|
|
|
JNIEnv* env, jobject obj, jstring j_path)
|
|
|
|
{
|
|
|
|
const std::string path = GetJString(env, j_path);
|
|
|
|
|
|
|
|
File::CreateFullPath(path);
|
|
|
|
|
|
|
|
IniFile ini;
|
|
|
|
|
|
|
|
EmulatedControllerFromJava(env, obj)->SaveConfig(ini.GetOrCreateSection("Profile"));
|
|
|
|
ini.Save(path);
|
|
|
|
}
|
|
|
|
|
2022-01-23 20:47:57 +00:00
|
|
|
JNIEXPORT jobject JNICALL
|
|
|
|
Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_EmulatedController_getGcPad(
|
|
|
|
JNIEnv* env, jclass, jint controller_index)
|
|
|
|
{
|
|
|
|
return EmulatedControllerToJava(env, Pad::GetConfig()->GetController(controller_index));
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jobject JNICALL
|
|
|
|
Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_EmulatedController_getWiimote(
|
|
|
|
JNIEnv* env, jclass, jint controller_index)
|
|
|
|
{
|
|
|
|
return EmulatedControllerToJava(env, Wiimote::GetConfig()->GetController(controller_index));
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jobject JNICALL
|
|
|
|
Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_EmulatedController_getWiimoteAttachment(
|
|
|
|
JNIEnv* env, jclass, jint controller_index, jint attachment_index)
|
|
|
|
{
|
|
|
|
auto* attachments = static_cast<ControllerEmu::Attachments*>(
|
|
|
|
Wiimote::GetWiimoteGroup(controller_index, WiimoteEmu::WiimoteGroup::Attachments));
|
|
|
|
return EmulatedControllerToJava(env, attachments->GetAttachmentList()[attachment_index].get());
|
|
|
|
}
|
|
|
|
}
|