From 9cbe66bce4e4de76200a4a15fe391a6963253cc9 Mon Sep 17 00:00:00 2001 From: Charles Lombardo Date: Wed, 1 Mar 2023 13:33:16 -0500 Subject: [PATCH] Android: Convert PatchCheat to Kotlin --- .../features/cheats/model/PatchCheat.java | 60 ------------------- .../features/cheats/model/PatchCheat.kt | 56 +++++++++++++++++ Source/Android/jni/AndroidCommon/IDCache.cpp | 2 +- Source/Android/jni/Cheats/PatchCheat.cpp | 2 +- 4 files changed, 58 insertions(+), 62 deletions(-) delete mode 100644 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/model/PatchCheat.java create mode 100644 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/model/PatchCheat.kt diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/model/PatchCheat.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/model/PatchCheat.java deleted file mode 100644 index 9dcb9f8111..0000000000 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/model/PatchCheat.java +++ /dev/null @@ -1,60 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later - -package org.dolphinemu.dolphinemu.features.cheats.model; - -import androidx.annotation.Keep; -import androidx.annotation.NonNull; - -public class PatchCheat extends AbstractCheat -{ - @Keep - private final long mPointer; - - public PatchCheat() - { - mPointer = createNew(); - } - - @Keep - private PatchCheat(long pointer) - { - mPointer = pointer; - } - - @Override - public native void finalize(); - - private native long createNew(); - - public boolean supportsCreator() - { - return false; - } - - public boolean supportsNotes() - { - return false; - } - - @NonNull - public native String getName(); - - @NonNull - public native String getCode(); - - public native boolean getUserDefined(); - - public native boolean getEnabled(); - - @Override - protected native int trySetImpl(@NonNull String name, @NonNull String creator, - @NonNull String notes, @NonNull String code); - - @Override - protected native void setEnabledImpl(boolean enabled); - - @NonNull - public static native PatchCheat[] loadCodes(String gameId, int revision); - - public static native void saveCodes(String gameId, int revision, PatchCheat[] codes); -} diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/model/PatchCheat.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/model/PatchCheat.kt new file mode 100644 index 0000000000..f4cd9660a4 --- /dev/null +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/model/PatchCheat.kt @@ -0,0 +1,56 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +package org.dolphinemu.dolphinemu.features.cheats.model + +import androidx.annotation.Keep + +class PatchCheat : AbstractCheat { + @Keep + private val pointer: Long + + constructor() { + pointer = createNew() + } + + @Keep + private constructor(pointer: Long) { + this.pointer = pointer + } + + external fun finalize() + + private external fun createNew(): Long + + override fun supportsCreator(): Boolean { + return false + } + + override fun supportsNotes(): Boolean { + return false + } + + external override fun getName(): String + + external override fun getCode(): String + + external override fun getUserDefined(): Boolean + + external override fun getEnabled(): Boolean + + external override fun setCheatImpl( + name: String, + creator: String, + notes: String, + code: String + ): Int + + external override fun setEnabledImpl(enabled: Boolean) + + companion object { + @JvmStatic + external fun loadCodes(gameId: String, revision: Int): Array + + @JvmStatic + external fun saveCodes(gameId: String, revision: Int, codes: Array) + } +} diff --git a/Source/Android/jni/AndroidCommon/IDCache.cpp b/Source/Android/jni/AndroidCommon/IDCache.cpp index da6050f643..8b84cb5dc4 100644 --- a/Source/Android/jni/AndroidCommon/IDCache.cpp +++ b/Source/Android/jni/AndroidCommon/IDCache.cpp @@ -514,7 +514,7 @@ JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) const jclass patch_cheat_class = env->FindClass("org/dolphinemu/dolphinemu/features/cheats/model/PatchCheat"); s_patch_cheat_class = reinterpret_cast(env->NewGlobalRef(patch_cheat_class)); - s_patch_cheat_pointer = env->GetFieldID(patch_cheat_class, "mPointer", "J"); + s_patch_cheat_pointer = env->GetFieldID(patch_cheat_class, "pointer", "J"); s_patch_cheat_constructor = env->GetMethodID(patch_cheat_class, "", "(J)V"); env->DeleteLocalRef(patch_cheat_class); diff --git a/Source/Android/jni/Cheats/PatchCheat.cpp b/Source/Android/jni/Cheats/PatchCheat.cpp index 7958fbdf1c..fb5be8d5b5 100644 --- a/Source/Android/jni/Cheats/PatchCheat.cpp +++ b/Source/Android/jni/Cheats/PatchCheat.cpp @@ -79,7 +79,7 @@ Java_org_dolphinemu_dolphinemu_features_cheats_model_PatchCheat_getEnabled(JNIEn return static_cast(GetPointer(env, obj)->enabled); } -JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_features_cheats_model_PatchCheat_trySetImpl( +JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_features_cheats_model_PatchCheat_setCheatImpl( JNIEnv* env, jobject obj, jstring name, jstring creator, jstring notes, jstring code_string) { PatchEngine::Patch* patch = GetPointer(env, obj);