Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #10092 from JosJuice/android-cheats
Android: Add cheat GUI
  • Loading branch information
leoetlino committed Sep 16, 2021
2 parents 4d1bd54 + 0ca4c6d commit 7379450
Show file tree
Hide file tree
Showing 41 changed files with 2,678 additions and 15 deletions.
2 changes: 2 additions & 0 deletions Source/Android/app/build.gradle
Expand Up @@ -90,6 +90,8 @@ dependencies {
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.lifecycle:lifecycle-viewmodel:2.3.1'
implementation 'androidx.fragment:fragment:1.3.6'
implementation "androidx.slidingpanelayout:slidingpanelayout:1.2.0-alpha03"
implementation 'com.google.android.material:material:1.4.0'

// Android TV UI libraries.
Expand Down
6 changes: 6 additions & 0 deletions Source/Android/app/src/main/AndroidManifest.xml
Expand Up @@ -76,6 +76,12 @@
android:theme="@style/DolphinSettingsBase"
android:label="@string/settings"/>

<activity
android:name=".features.cheats.ui.CheatsActivity"
android:exported="false"
android:theme="@style/DolphinSettingsBase"
android:label="@string/cheats"/>

<activity
android:name=".activities.EmulationActivity"
android:exported="false"
Expand Down
Expand Up @@ -12,6 +12,7 @@

import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.activities.ConvertActivity;
import org.dolphinemu.dolphinemu.features.cheats.ui.CheatsActivity;
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
import org.dolphinemu.dolphinemu.features.settings.model.StringSetting;
import org.dolphinemu.dolphinemu.features.settings.ui.MenuTag;
Expand All @@ -28,7 +29,8 @@ public class GamePropertiesDialog extends DialogFragment
{
public static final String TAG = "GamePropertiesDialog";
private static final String ARG_PATH = "path";
private static final String ARG_GAMEID = "game_id";
private static final String ARG_GAME_ID = "game_id";
private static final String ARG_GAMETDB_ID = "gametdb_id";
public static final String ARG_REVISION = "revision";
private static final String ARG_PLATFORM = "platform";
private static final String ARG_SHOULD_ALLOW_CONVERSION = "should_allow_conversion";
Expand All @@ -39,7 +41,8 @@ public static GamePropertiesDialog newInstance(GameFile gameFile)

Bundle arguments = new Bundle();
arguments.putString(ARG_PATH, gameFile.getPath());
arguments.putString(ARG_GAMEID, gameFile.getGameId());
arguments.putString(ARG_GAME_ID, gameFile.getGameId());
arguments.putString(ARG_GAMETDB_ID, gameFile.getGameTdbId());
arguments.putInt(ARG_REVISION, gameFile.getRevision());
arguments.putInt(ARG_PLATFORM, gameFile.getPlatform());
arguments.putBoolean(ARG_SHOULD_ALLOW_CONVERSION, gameFile.shouldAllowConversion());
Expand All @@ -53,7 +56,8 @@ public static GamePropertiesDialog newInstance(GameFile gameFile)
public Dialog onCreateDialog(Bundle savedInstanceState)
{
final String path = requireArguments().getString(ARG_PATH);
final String gameId = requireArguments().getString(ARG_GAMEID);
final String gameId = requireArguments().getString(ARG_GAME_ID);
final String gameTdbId = requireArguments().getString(ARG_GAMETDB_ID);
final int revision = requireArguments().getInt(ARG_REVISION);
final int platform = requireArguments().getInt(ARG_PLATFORM);
final boolean shouldAllowConversion =
Expand Down Expand Up @@ -91,6 +95,9 @@ public Dialog onCreateDialog(Bundle savedInstanceState)
itemsBuilder.add(R.string.properties_edit_game_settings, (dialog, i) ->
SettingsActivity.launch(getContext(), MenuTag.SETTINGS, gameId, revision, isWii));

itemsBuilder.add(R.string.properties_edit_cheats, (dialog, i) ->
CheatsActivity.launch(getContext(), gameId, gameTdbId, revision, isWii));

itemsBuilder.add(R.string.properties_clear_game_settings, (dialog, i) ->
clearGameSettings(gameId));

Expand Down
@@ -0,0 +1,60 @@
// 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 ARCheat extends AbstractCheat
{
@Keep
private final long mPointer;

public ARCheat()
{
mPointer = createNew();
}

@Keep
private ARCheat(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 ARCheat[] loadCodes(String gameId, int revision);

public static native void saveCodes(String gameId, int revision, ARCheat[] codes);
}
@@ -0,0 +1,62 @@
// SPDX-License-Identifier: GPL-2.0-or-later

package org.dolphinemu.dolphinemu.features.cheats.model;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

public abstract class AbstractCheat implements Cheat
{
private Runnable mChangedCallback = null;

public int trySet(@NonNull String name, @NonNull String creator, @NonNull String notes,
@NonNull String code)
{
if (!code.isEmpty() && code.charAt(0) == '$')
{
int firstLineEnd = code.indexOf('\n');
if (firstLineEnd == -1)
{
name = code.substring(1);
code = "";
}
else
{
name = code.substring(1, firstLineEnd);
code = code.substring(firstLineEnd + 1);
}
}

if (name.isEmpty())
return TRY_SET_FAIL_NO_NAME;

int result = trySetImpl(name, creator, notes, code);

if (result == TRY_SET_SUCCESS)
onChanged();

return result;
}

public void setEnabled(boolean enabled)
{
setEnabledImpl(enabled);
onChanged();
}

public void setChangedCallback(@Nullable Runnable callback)
{
mChangedCallback = callback;
}

protected void onChanged()
{
if (mChangedCallback != null)
mChangedCallback.run();
}

protected abstract int trySetImpl(@NonNull String name, @NonNull String creator,
@NonNull String notes, @NonNull String code);

protected abstract void setEnabledImpl(boolean enabled);
}
@@ -0,0 +1,48 @@
// SPDX-License-Identifier: GPL-2.0-or-later

package org.dolphinemu.dolphinemu.features.cheats.model;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

public interface Cheat
{
int TRY_SET_FAIL_CODE_MIXED_ENCRYPTION = -3;
int TRY_SET_FAIL_NO_CODE_LINES = -2;
int TRY_SET_FAIL_NO_NAME = -1;
int TRY_SET_SUCCESS = 0;
// Result codes greater than 0 represent an error on the corresponding code line (one-indexed)

boolean supportsCreator();

boolean supportsNotes();

@NonNull
String getName();

@NonNull
default String getCreator()
{
return "";
}

@NonNull
default String getNotes()
{
return "";
}

@NonNull
String getCode();

int trySet(@NonNull String name, @NonNull String creator, @NonNull String notes,
@NonNull String code);

boolean getUserDefined();

boolean getEnabled();

void setEnabled(boolean enabled);

void setChangedCallback(@Nullable Runnable callback);
}

0 comments on commit 7379450

Please sign in to comment.