mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 06:09:50 -06:00
Android: Allow viewing/editing the actual codes
This commit is contained in:
@ -8,6 +8,8 @@
|
||||
|
||||
#include "Common/FileUtil.h"
|
||||
#include "Common/IniFile.h"
|
||||
#include "Common/StringUtil.h"
|
||||
#include "Core/ARDecrypt.h"
|
||||
#include "Core/ActionReplay.h"
|
||||
#include "Core/ConfigManager.h"
|
||||
#include "jni/AndroidCommon/AndroidCommon.h"
|
||||
@ -40,6 +42,24 @@ Java_org_dolphinemu_dolphinemu_features_cheats_model_ARCheat_getName(JNIEnv* env
|
||||
return ToJString(env, GetPointer(env, obj)->name);
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_org_dolphinemu_dolphinemu_features_cheats_model_ARCheat_getCode(JNIEnv* env, jobject obj)
|
||||
{
|
||||
ActionReplay::ARCode* code = GetPointer(env, obj);
|
||||
|
||||
std::string code_string;
|
||||
|
||||
for (size_t i = 0; i < code->ops.size(); ++i)
|
||||
{
|
||||
if (i != 0)
|
||||
code_string += '\n';
|
||||
|
||||
code_string += ActionReplay::SerializeLine(code->ops[i]);
|
||||
}
|
||||
|
||||
return ToJString(env, code_string);
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_org_dolphinemu_dolphinemu_features_cheats_model_ARCheat_getUserDefined(JNIEnv* env,
|
||||
jobject obj)
|
||||
@ -54,12 +74,47 @@ Java_org_dolphinemu_dolphinemu_features_cheats_model_ARCheat_getEnabled(JNIEnv*
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_features_cheats_model_ARCheat_trySetImpl(
|
||||
JNIEnv* env, jobject obj, jstring name)
|
||||
JNIEnv* env, jobject obj, jstring name, jstring code_string)
|
||||
{
|
||||
ActionReplay::ARCode* code = GetPointer(env, obj);
|
||||
code->name = GetJString(env, name);
|
||||
|
||||
return TRY_SET_SUCCESS;
|
||||
std::vector<ActionReplay::AREntry> entries;
|
||||
std::vector<std::string> encrypted_lines;
|
||||
|
||||
std::vector<std::string> lines = SplitString(GetJString(env, code_string), '\n');
|
||||
|
||||
for (size_t i = 0; i < lines.size(); i++)
|
||||
{
|
||||
const std::string& line = lines[i];
|
||||
|
||||
if (line.empty())
|
||||
continue;
|
||||
|
||||
auto parse_result = ActionReplay::DeserializeLine(line);
|
||||
|
||||
if (std::holds_alternative<ActionReplay::AREntry>(parse_result))
|
||||
entries.emplace_back(std::get<ActionReplay::AREntry>(std::move(parse_result)));
|
||||
else if (std::holds_alternative<ActionReplay::EncryptedLine>(parse_result))
|
||||
encrypted_lines.emplace_back(std::get<ActionReplay::EncryptedLine>(std::move(parse_result)));
|
||||
else
|
||||
return i + 1; // Parse error on line i
|
||||
}
|
||||
|
||||
if (!encrypted_lines.empty())
|
||||
{
|
||||
if (!entries.empty())
|
||||
return Cheats::TRY_SET_FAIL_CODE_MIXED_ENCRYPTION;
|
||||
|
||||
ActionReplay::DecryptARCode(encrypted_lines, &entries);
|
||||
}
|
||||
|
||||
if (entries.empty())
|
||||
return Cheats::TRY_SET_FAIL_NO_CODE_LINES;
|
||||
|
||||
code->name = GetJString(env, name);
|
||||
code->ops = std::move(entries);
|
||||
|
||||
return Cheats::TRY_SET_SUCCESS;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_features_cheats_model_ARCheat_setEnabledImpl(
|
||||
|
@ -3,5 +3,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace Cheats
|
||||
{
|
||||
constexpr int TRY_SET_FAIL_CODE_MIXED_ENCRYPTION = -3;
|
||||
constexpr int TRY_SET_FAIL_NO_CODE_LINES = -2;
|
||||
constexpr int TRY_SET_FAIL_NO_NAME = -1;
|
||||
constexpr int TRY_SET_SUCCESS = 0;
|
||||
// Result codes greater than 0 represent an error on the corresponding code line (one-indexed)
|
||||
} // namespace Cheats
|
||||
|
@ -41,6 +41,24 @@ Java_org_dolphinemu_dolphinemu_features_cheats_model_GeckoCheat_getName(JNIEnv*
|
||||
return ToJString(env, GetPointer(env, obj)->name);
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_org_dolphinemu_dolphinemu_features_cheats_model_GeckoCheat_getCode(JNIEnv* env, jobject obj)
|
||||
{
|
||||
Gecko::GeckoCode* code = GetPointer(env, obj);
|
||||
|
||||
std::string code_string;
|
||||
|
||||
for (size_t i = 0; i < code->codes.size(); ++i)
|
||||
{
|
||||
if (i != 0)
|
||||
code_string += '\n';
|
||||
|
||||
code_string += code->codes[i].original_line;
|
||||
}
|
||||
|
||||
return ToJString(env, code_string);
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_org_dolphinemu_dolphinemu_features_cheats_model_GeckoCheat_getUserDefined(JNIEnv* env,
|
||||
jobject obj)
|
||||
@ -55,12 +73,34 @@ Java_org_dolphinemu_dolphinemu_features_cheats_model_GeckoCheat_getEnabled(JNIEn
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_features_cheats_model_GeckoCheat_trySetImpl(
|
||||
JNIEnv* env, jobject obj, jstring name)
|
||||
JNIEnv* env, jobject obj, jstring name, jstring code_string)
|
||||
{
|
||||
Gecko::GeckoCode* code = GetPointer(env, obj);
|
||||
code->name = GetJString(env, name);
|
||||
|
||||
return TRY_SET_SUCCESS;
|
||||
std::vector<Gecko::GeckoCode::Code> entries;
|
||||
|
||||
std::vector<std::string> lines = SplitString(GetJString(env, code_string), '\n');
|
||||
|
||||
for (size_t i = 0; i < lines.size(); i++)
|
||||
{
|
||||
const std::string& line = lines[i];
|
||||
|
||||
if (line.empty())
|
||||
continue;
|
||||
|
||||
if (std::optional<Gecko::GeckoCode::Code> c = Gecko::DeserializeLine(line))
|
||||
entries.emplace_back(*std::move(c));
|
||||
else
|
||||
return i + 1; // Parse error on line i
|
||||
}
|
||||
|
||||
if (entries.empty())
|
||||
return Cheats::TRY_SET_FAIL_NO_CODE_LINES;
|
||||
|
||||
code->name = GetJString(env, name);
|
||||
code->codes = std::move(entries);
|
||||
|
||||
return Cheats::TRY_SET_SUCCESS;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
|
@ -40,6 +40,24 @@ Java_org_dolphinemu_dolphinemu_features_cheats_model_PatchCheat_getName(JNIEnv*
|
||||
return ToJString(env, GetPointer(env, obj)->name);
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_org_dolphinemu_dolphinemu_features_cheats_model_PatchCheat_getCode(JNIEnv* env, jobject obj)
|
||||
{
|
||||
PatchEngine::Patch* patch = GetPointer(env, obj);
|
||||
|
||||
std::string code_string;
|
||||
|
||||
for (size_t i = 0; i < patch->entries.size(); ++i)
|
||||
{
|
||||
if (i != 0)
|
||||
code_string += '\n';
|
||||
|
||||
code_string += PatchEngine::SerializeLine(patch->entries[i]);
|
||||
}
|
||||
|
||||
return ToJString(env, code_string);
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_org_dolphinemu_dolphinemu_features_cheats_model_PatchCheat_getUserDefined(JNIEnv* env,
|
||||
jobject obj)
|
||||
@ -54,12 +72,34 @@ Java_org_dolphinemu_dolphinemu_features_cheats_model_PatchCheat_getEnabled(JNIEn
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_features_cheats_model_PatchCheat_trySetImpl(
|
||||
JNIEnv* env, jobject obj, jstring name)
|
||||
JNIEnv* env, jobject obj, jstring name, jstring code_string)
|
||||
{
|
||||
PatchEngine::Patch* patch = GetPointer(env, obj);
|
||||
patch->name = GetJString(env, name);
|
||||
|
||||
return TRY_SET_SUCCESS;
|
||||
std::vector<PatchEngine::PatchEntry> entries;
|
||||
|
||||
std::vector<std::string> lines = SplitString(GetJString(env, code_string), '\n');
|
||||
|
||||
for (size_t i = 0; i < lines.size(); i++)
|
||||
{
|
||||
const std::string& line = lines[i];
|
||||
|
||||
if (line.empty())
|
||||
continue;
|
||||
|
||||
if (std::optional<PatchEngine::PatchEntry> entry = PatchEngine::DeserializeLine(line))
|
||||
entries.emplace_back(*std::move(entry));
|
||||
else
|
||||
return i + 1; // Parse error on line i
|
||||
}
|
||||
|
||||
if (entries.empty())
|
||||
return Cheats::TRY_SET_FAIL_NO_CODE_LINES;
|
||||
|
||||
patch->name = GetJString(env, name);
|
||||
patch->entries = std::move(entries);
|
||||
|
||||
return Cheats::TRY_SET_SUCCESS;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
|
Reference in New Issue
Block a user