mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-06-16 12:58:33 +02: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(
|
||||
|
Reference in New Issue
Block a user