mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 14:19:46 -06:00
Android: Add graphics mods support to CheatsActivity
This commit is contained in:
@ -70,6 +70,14 @@ static jclass s_patch_cheat_class;
|
||||
static jfieldID s_patch_cheat_pointer;
|
||||
static jmethodID s_patch_cheat_constructor;
|
||||
|
||||
static jclass s_graphics_mod_group_class;
|
||||
static jfieldID s_graphics_mod_group_pointer;
|
||||
static jmethodID s_graphics_mod_group_constructor;
|
||||
|
||||
static jclass s_graphics_mod_class;
|
||||
static jfieldID s_graphics_mod_pointer;
|
||||
static jmethodID s_graphics_mod_constructor;
|
||||
|
||||
static jclass s_riivolution_patches_class;
|
||||
static jfieldID s_riivolution_patches_pointer;
|
||||
|
||||
@ -331,6 +339,36 @@ jmethodID GetPatchCheatConstructor()
|
||||
return s_patch_cheat_constructor;
|
||||
}
|
||||
|
||||
jclass GetGraphicsModClass()
|
||||
{
|
||||
return s_graphics_mod_class;
|
||||
}
|
||||
|
||||
jfieldID GetGraphicsModPointer()
|
||||
{
|
||||
return s_graphics_mod_pointer;
|
||||
}
|
||||
|
||||
jmethodID GetGraphicsModConstructor()
|
||||
{
|
||||
return s_graphics_mod_constructor;
|
||||
}
|
||||
|
||||
jclass GetGraphicsModGroupClass()
|
||||
{
|
||||
return s_graphics_mod_group_class;
|
||||
}
|
||||
|
||||
jfieldID GetGraphicsModGroupPointer()
|
||||
{
|
||||
return s_graphics_mod_group_pointer;
|
||||
}
|
||||
|
||||
jmethodID GetGraphicsModGroupConstructor()
|
||||
{
|
||||
return s_graphics_mod_group_constructor;
|
||||
}
|
||||
|
||||
jclass GetRiivolutionPatchesClass()
|
||||
{
|
||||
return s_riivolution_patches_class;
|
||||
@ -480,6 +518,23 @@ JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved)
|
||||
s_patch_cheat_constructor = env->GetMethodID(patch_cheat_class, "<init>", "(J)V");
|
||||
env->DeleteLocalRef(patch_cheat_class);
|
||||
|
||||
const jclass graphics_mod_group_class =
|
||||
env->FindClass("org/dolphinemu/dolphinemu/features/cheats/model/GraphicsModGroup");
|
||||
s_graphics_mod_group_class =
|
||||
reinterpret_cast<jclass>(env->NewGlobalRef(graphics_mod_group_class));
|
||||
s_graphics_mod_group_pointer = env->GetFieldID(graphics_mod_group_class, "mPointer", "J");
|
||||
s_graphics_mod_group_constructor = env->GetMethodID(graphics_mod_group_class, "<init>", "(J)V");
|
||||
env->DeleteLocalRef(graphics_mod_group_class);
|
||||
|
||||
const jclass graphics_mod_class =
|
||||
env->FindClass("org/dolphinemu/dolphinemu/features/cheats/model/GraphicsMod");
|
||||
s_graphics_mod_class = reinterpret_cast<jclass>(env->NewGlobalRef(graphics_mod_class));
|
||||
s_graphics_mod_pointer = env->GetFieldID(graphics_mod_class, "mPointer", "J");
|
||||
s_graphics_mod_constructor =
|
||||
env->GetMethodID(graphics_mod_class, "<init>",
|
||||
"(JLorg/dolphinemu/dolphinemu/features/cheats/model/GraphicsModGroup;)V");
|
||||
env->DeleteLocalRef(graphics_mod_class);
|
||||
|
||||
const jclass riivolution_patches_class =
|
||||
env->FindClass("org/dolphinemu/dolphinemu/features/riivolution/model/RiivolutionPatches");
|
||||
s_riivolution_patches_class =
|
||||
@ -516,6 +571,8 @@ JNIEXPORT void JNI_OnUnload(JavaVM* vm, void* reserved)
|
||||
env->DeleteGlobalRef(s_ar_cheat_class);
|
||||
env->DeleteGlobalRef(s_gecko_cheat_class);
|
||||
env->DeleteGlobalRef(s_patch_cheat_class);
|
||||
env->DeleteGlobalRef(s_graphics_mod_group_class);
|
||||
env->DeleteGlobalRef(s_graphics_mod_class);
|
||||
env->DeleteGlobalRef(s_riivolution_patches_class);
|
||||
env->DeleteGlobalRef(s_wii_update_cb_class);
|
||||
}
|
||||
|
@ -69,6 +69,14 @@ jclass GetPatchCheatClass();
|
||||
jfieldID GetPatchCheatPointer();
|
||||
jmethodID GetPatchCheatConstructor();
|
||||
|
||||
jclass GetGraphicsModGroupClass();
|
||||
jfieldID GetGraphicsModGroupPointer();
|
||||
jmethodID GetGraphicsModGroupConstructor();
|
||||
|
||||
jclass GetGraphicsModClass();
|
||||
jfieldID GetGraphicsModPointer();
|
||||
jmethodID GetGraphicsModConstructor();
|
||||
|
||||
jclass GetRiivolutionPatchesClass();
|
||||
jfieldID GetRiivolutionPatchesPointer();
|
||||
|
||||
|
@ -2,6 +2,8 @@ add_library(main SHARED
|
||||
Cheats/ARCheat.cpp
|
||||
Cheats/Cheats.h
|
||||
Cheats/GeckoCheat.cpp
|
||||
Cheats/GraphicsMod.cpp
|
||||
Cheats/GraphicsModGroup.cpp
|
||||
Cheats/PatchCheat.cpp
|
||||
Config/NativeConfig.cpp
|
||||
Config/PostProcessing.cpp
|
||||
|
53
Source/Android/jni/Cheats/GraphicsMod.cpp
Normal file
53
Source/Android/jni/Cheats/GraphicsMod.cpp
Normal file
@ -0,0 +1,53 @@
|
||||
// Copyright 2022 Dolphin Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
#include "VideoCommon/GraphicsModSystem/Config/GraphicsMod.h"
|
||||
#include "jni/AndroidCommon/AndroidCommon.h"
|
||||
#include "jni/AndroidCommon/IDCache.h"
|
||||
|
||||
static GraphicsModConfig* GetPointer(JNIEnv* env, jobject obj)
|
||||
{
|
||||
return reinterpret_cast<GraphicsModConfig*>(
|
||||
env->GetLongField(obj, IDCache::GetGraphicsModPointer()));
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_org_dolphinemu_dolphinemu_features_cheats_model_GraphicsMod_getName(JNIEnv* env, jobject obj)
|
||||
{
|
||||
return ToJString(env, GetPointer(env, obj)->m_title);
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_org_dolphinemu_dolphinemu_features_cheats_model_GraphicsMod_getCreator(JNIEnv* env,
|
||||
jobject obj)
|
||||
{
|
||||
return ToJString(env, GetPointer(env, obj)->m_author);
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_org_dolphinemu_dolphinemu_features_cheats_model_GraphicsMod_getNotes(JNIEnv* env, jobject obj)
|
||||
{
|
||||
return ToJString(env, GetPointer(env, obj)->m_description);
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_org_dolphinemu_dolphinemu_features_cheats_model_GraphicsMod_getEnabled(JNIEnv* env,
|
||||
jobject obj)
|
||||
{
|
||||
return static_cast<jboolean>(GetPointer(env, obj)->m_enabled);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_dolphinemu_dolphinemu_features_cheats_model_GraphicsMod_setEnabledImpl(JNIEnv* env,
|
||||
jobject obj,
|
||||
jboolean enabled)
|
||||
{
|
||||
GetPointer(env, obj)->m_enabled = static_cast<bool>(enabled);
|
||||
}
|
||||
}
|
92
Source/Android/jni/Cheats/GraphicsModGroup.cpp
Normal file
92
Source/Android/jni/Cheats/GraphicsModGroup.cpp
Normal file
@ -0,0 +1,92 @@
|
||||
// Copyright 2022 Dolphin Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
#include "VideoCommon/GraphicsModSystem/Config/GraphicsMod.h"
|
||||
#include "VideoCommon/GraphicsModSystem/Config/GraphicsModGroup.h"
|
||||
#include "jni/AndroidCommon/AndroidCommon.h"
|
||||
#include "jni/AndroidCommon/IDCache.h"
|
||||
|
||||
static GraphicsModGroupConfig* GetPointer(JNIEnv* env, jobject obj)
|
||||
{
|
||||
return reinterpret_cast<GraphicsModGroupConfig*>(
|
||||
env->GetLongField(obj, IDCache::GetGraphicsModGroupPointer()));
|
||||
}
|
||||
|
||||
jobject GraphicsModToJava(JNIEnv* env, GraphicsModConfig* mod, jobject jGraphicsModGroup)
|
||||
{
|
||||
return env->NewObject(IDCache::GetGraphicsModClass(), IDCache::GetGraphicsModConstructor(),
|
||||
reinterpret_cast<jlong>(mod), jGraphicsModGroup);
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_dolphinemu_dolphinemu_features_cheats_model_GraphicsModGroup_finalize(JNIEnv* env,
|
||||
jobject obj)
|
||||
{
|
||||
delete GetPointer(env, obj);
|
||||
}
|
||||
|
||||
JNIEXPORT jobjectArray JNICALL
|
||||
Java_org_dolphinemu_dolphinemu_features_cheats_model_GraphicsModGroup_getMods(JNIEnv* env,
|
||||
jobject obj)
|
||||
{
|
||||
GraphicsModGroupConfig* mod_group = GetPointer(env, obj);
|
||||
|
||||
std::set<std::string> groups;
|
||||
|
||||
for (const GraphicsModConfig& mod : mod_group->GetMods())
|
||||
{
|
||||
for (const GraphicsTargetGroupConfig& group : mod.m_groups)
|
||||
groups.insert(group.m_name);
|
||||
}
|
||||
|
||||
std::vector<GraphicsModConfig*> mods;
|
||||
|
||||
for (GraphicsModConfig& mod : mod_group->GetMods())
|
||||
{
|
||||
// If no group matches the mod's features, or if the mod has no features, skip it
|
||||
if (std::none_of(mod.m_features.begin(), mod.m_features.end(),
|
||||
[&groups](const GraphicsModFeatureConfig& feature) {
|
||||
return groups.count(feature.m_group) == 1;
|
||||
}))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
mods.push_back(&mod);
|
||||
}
|
||||
|
||||
const jobjectArray array =
|
||||
env->NewObjectArray(static_cast<jsize>(mods.size()), IDCache::GetGraphicsModClass(), nullptr);
|
||||
|
||||
jsize i = 0;
|
||||
for (GraphicsModConfig* mod : mods)
|
||||
env->SetObjectArrayElement(array, i++, GraphicsModToJava(env, mod, obj));
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_dolphinemu_dolphinemu_features_cheats_model_GraphicsModGroup_save(JNIEnv* env, jobject obj)
|
||||
{
|
||||
GetPointer(env, obj)->Save();
|
||||
}
|
||||
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_org_dolphinemu_dolphinemu_features_cheats_model_GraphicsModGroup_load(JNIEnv* env, jclass,
|
||||
jstring jGameId)
|
||||
{
|
||||
auto* mod_group = new GraphicsModGroupConfig(GetJString(env, jGameId));
|
||||
|
||||
mod_group->Load();
|
||||
|
||||
return env->NewObject(IDCache::GetGraphicsModGroupClass(),
|
||||
IDCache::GetGraphicsModGroupConstructor(), mod_group);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user