Skip to content

Commit

Permalink
Merge pull request dolphin-emu#10184 from JosJuice/android-riivolution
Browse files Browse the repository at this point in the history
Android: Allow starting game with Riivolution patches from the GUI
  • Loading branch information
JosJuice authored Oct 31, 2021
2 parents fb8b9f3 + 8b0624f commit 96a6d6f
Showing 26 changed files with 822 additions and 37 deletions.
5 changes: 5 additions & 0 deletions Source/Android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -127,6 +127,11 @@
android:label="@string/user_data_submenu"
android:theme="@style/DolphinSettingsBase" />

<activity
android:name=".features.riivolution.ui.RiivolutionBootActivity"
android:exported="false"
android:theme="@style/DolphinBase" />

<service
android:name=".utils.DirectoryInitialization"
android:exported="false"/>
Original file line number Diff line number Diff line change
@@ -379,12 +379,13 @@ public static native void SetMotionSensorsEnabled(boolean accelerometerEnabled,
/**
* Begins emulation.
*/
public static native void Run(String[] path);
public static native void Run(String[] path, boolean riivolution);

/**
* Begins emulation from the specified savestate.
*/
public static native void Run(String[] path, String savestatePath, boolean deleteSavestate);
public static native void Run(String[] path, boolean riivolution, String savestatePath,
boolean deleteSavestate);

public static native void ChangeDisc(String path);

Original file line number Diff line number Diff line change
@@ -140,6 +140,6 @@ private void startGame(GameFile game)
mAfterDirectoryInitializationRunner.cancel();
mAfterDirectoryInitializationRunner = null;
}
EmulationActivity.launch(this, GameFileCacheService.findSecondDiscAndGetPaths(game));
EmulationActivity.launch(this, GameFileCacheService.findSecondDiscAndGetPaths(game), false);
}
}
Original file line number Diff line number Diff line change
@@ -79,11 +79,13 @@ public final class EmulationActivity extends AppCompatActivity

private boolean activityRecreated;
private String[] mPaths;
private boolean mRiivolution;
private boolean mIgnoreWarnings;
private static boolean sUserPausedEmulation;
private boolean mMenuToastShown;

public static final String EXTRA_SELECTED_GAMES = "SelectedGames";
public static final String EXTRA_RIIVOLUTION = "Riivolution";
public static final String EXTRA_IGNORE_WARNINGS = "IgnoreWarnings";
public static final String EXTRA_USER_PAUSED_EMULATION = "sUserPausedEmulation";
public static final String EXTRA_MENU_TOAST_SHOWN = "MenuToastShown";
@@ -164,12 +166,12 @@ public final class EmulationActivity extends AppCompatActivity
EmulationActivity.MENU_ACTION_MOTION_CONTROLS);
}

public static void launch(FragmentActivity activity, String filePath)
public static void launch(FragmentActivity activity, String filePath, boolean riivolution)
{
launch(activity, new String[]{filePath});
launch(activity, new String[]{filePath}, riivolution);
}

public static void launch(FragmentActivity activity, String[] filePaths)
public static void launch(FragmentActivity activity, String[] filePaths, boolean riivolution)
{
if (sIgnoreLaunchRequests)
return;
@@ -183,7 +185,7 @@ public static void launch(FragmentActivity activity, String[] filePaths)
FileBrowserHelper.isPathEmptyOrValid(StringSetting.MAIN_RESOURCEPACK_PATH) &&
FileBrowserHelper.isPathEmptyOrValid(StringSetting.MAIN_SD_PATH))
{
launchWithoutChecks(activity, filePaths);
launchWithoutChecks(activity, filePaths, riivolution);
}
else
{
@@ -192,18 +194,20 @@ public static void launch(FragmentActivity activity, String[] filePaths)
builder.setPositiveButton(R.string.yes, (dialogInterface, i) ->
SettingsActivity.launch(activity, MenuTag.CONFIG_PATHS));
builder.setNeutralButton(R.string.continue_anyway, (dialogInterface, i) ->
launchWithoutChecks(activity, filePaths));
launchWithoutChecks(activity, filePaths, riivolution));
builder.show();
}
});
}

private static void launchWithoutChecks(FragmentActivity activity, String[] filePaths)
private static void launchWithoutChecks(FragmentActivity activity, String[] filePaths,
boolean riivolution)
{
sIgnoreLaunchRequests = true;

Intent launcher = new Intent(activity, EmulationActivity.class);
launcher.putExtra(EXTRA_SELECTED_GAMES, filePaths);
launcher.putExtra(EXTRA_RIIVOLUTION, riivolution);

activity.startActivity(launcher);
}
@@ -251,6 +255,7 @@ protected void onCreate(Bundle savedInstanceState)
// Get params we were passed
Intent gameToEmulate = getIntent();
mPaths = gameToEmulate.getStringArrayExtra(EXTRA_SELECTED_GAMES);
mRiivolution = gameToEmulate.getBooleanExtra(EXTRA_RIIVOLUTION, false);
mIgnoreWarnings = gameToEmulate.getBooleanExtra(EXTRA_IGNORE_WARNINGS, false);
sUserPausedEmulation = gameToEmulate.getBooleanExtra(EXTRA_USER_PAUSED_EMULATION, false);
mMenuToastShown = false;
@@ -283,7 +288,7 @@ protected void onCreate(Bundle savedInstanceState)
.findFragmentById(R.id.frame_emulation_fragment);
if (mEmulationFragment == null)
{
mEmulationFragment = EmulationFragment.newInstance(mPaths);
mEmulationFragment = EmulationFragment.newInstance(mPaths, mRiivolution);
getSupportFragmentManager().beginTransaction()
.add(R.id.frame_emulation_fragment, mEmulationFragment)
.commit();
Original file line number Diff line number Diff line change
@@ -141,7 +141,7 @@ public void onClick(View view)
GameViewHolder holder = (GameViewHolder) view.getTag();

String[] paths = GameFileCacheService.findSecondDiscAndGetPaths(holder.gameFile);
EmulationActivity.launch((FragmentActivity) view.getContext(), paths);
EmulationActivity.launch((FragmentActivity) view.getContext(), paths, false);
}

/**
Original file line number Diff line number Diff line change
@@ -15,6 +15,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.riivolution.ui.RiivolutionBootActivity;
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
import org.dolphinemu.dolphinemu.features.settings.model.StringSetting;
import org.dolphinemu.dolphinemu.features.settings.ui.MenuTag;
@@ -34,6 +35,7 @@ public class GamePropertiesDialog extends DialogFragment
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";
public static final String ARG_DISC_NUMBER = "disc_number";
private static final String ARG_PLATFORM = "platform";
private static final String ARG_SHOULD_ALLOW_CONVERSION = "should_allow_conversion";

@@ -46,6 +48,7 @@ public static GamePropertiesDialog newInstance(GameFile gameFile)
arguments.putString(ARG_GAME_ID, gameFile.getGameId());
arguments.putString(ARG_GAMETDB_ID, gameFile.getGameTdbId());
arguments.putInt(ARG_REVISION, gameFile.getRevision());
arguments.putInt(ARG_DISC_NUMBER, gameFile.getDiscNumber());
arguments.putInt(ARG_PLATFORM, gameFile.getPlatform());
arguments.putBoolean(ARG_SHOULD_ALLOW_CONVERSION, gameFile.shouldAllowConversion());
fragment.setArguments(arguments);
@@ -61,6 +64,7 @@ public Dialog onCreateDialog(Bundle savedInstanceState)
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 discNumber = requireArguments().getInt(ARG_DISC_NUMBER);
final int platform = requireArguments().getInt(ARG_PLATFORM);
final boolean shouldAllowConversion =
requireArguments().getBoolean(ARG_SHOULD_ALLOW_CONVERSION);
@@ -75,14 +79,11 @@ public Dialog onCreateDialog(Bundle savedInstanceState)
GameDetailsDialog.newInstance(path).show(requireActivity()
.getSupportFragmentManager(), "game_details"));

if (shouldAllowConversion)
{
itemsBuilder.add(R.string.properties_convert, (dialog, i) ->
ConvertActivity.launch(getContext(), path));
}

if (isDisc)
{
itemsBuilder.add(R.string.properties_start_with_riivolution, (dialog, i) ->
RiivolutionBootActivity.launch(getContext(), path, gameId, revision, discNumber));

itemsBuilder.add(R.string.properties_set_default_iso, (dialog, i) ->
{
try (Settings settings = new Settings())
@@ -94,6 +95,12 @@ public Dialog onCreateDialog(Bundle savedInstanceState)
});
}

if (shouldAllowConversion)
{
itemsBuilder.add(R.string.properties_convert, (dialog, i) ->
ConvertActivity.launch(getContext(), path));
}

itemsBuilder.add(R.string.properties_edit_game_settings, (dialog, i) ->
SettingsActivity.launch(getContext(), MenuTag.SETTINGS, gameId, revision, isWii));

Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// SPDX-License-Identifier: GPL-2.0-or-later

package org.dolphinemu.dolphinemu.features.riivolution.model;

import androidx.annotation.Keep;

public class RiivolutionPatches
{
private String mGameId;
private int mRevision;
private int mDiscNumber;

private boolean mUnsavedChanges = false;

@Keep
private long mPointer;

public RiivolutionPatches(String gameId, int revision, int discNumber)
{
mGameId = gameId;
mRevision = revision;
mDiscNumber = discNumber;

mPointer = initialize();
}

@Override
public native void finalize();

private static native long initialize();

public native int getDiscCount();

public native String getDiscName(int discIndex);

public native int getSectionCount(int discIndex);

public native String getSectionName(int discIndex, int sectionIndex);

public native int getOptionCount(int discIndex, int sectionIndex);

public native String getOptionName(int discIndex, int sectionIndex, int optionIndex);

public native int getChoiceCount(int discIndex, int sectionIndex, int optionIndex);

public native String getChoiceName(int discIndex, int sectionIndex, int optionIndex,
int choiceIndex);

/**
* @return 0 if no choice is selected, otherwise the index of the selected choice plus one.
*/
public native int getSelectedChoice(int discIndex, int sectionIndex, int optionIndex);

/**
* @param choiceIndex 0 to select no choice, otherwise the choice index plus one.
*/
public void setSelectedChoice(int discIndex, int sectionIndex, int optionIndex, int choiceIndex)
{
mUnsavedChanges = true;
setSelectedChoiceImpl(discIndex, sectionIndex, optionIndex, choiceIndex);
}

/**
* @param choiceIndex 0 to select no choice, otherwise the choice index plus one.
*/
private native void setSelectedChoiceImpl(int discIndex, int sectionIndex, int optionIndex,
int choiceIndex);

public void loadConfig()
{
loadConfigImpl(mGameId, mRevision, mDiscNumber);
}

private native void loadConfigImpl(String gameId, int revision, int discNumber);

public void saveConfig()
{
if (mUnsavedChanges)
{
mUnsavedChanges = false;
saveConfigImpl(mGameId);
}
}

private native void saveConfigImpl(String gameId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// SPDX-License-Identifier: GPL-2.0-or-later

package org.dolphinemu.dolphinemu.features.riivolution.ui;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.features.riivolution.model.RiivolutionPatches;

import java.util.ArrayList;

public class RiivolutionAdapter extends RecyclerView.Adapter<RiivolutionViewHolder>
{
private final Context mContext;
private final RiivolutionPatches mPatches;
private final ArrayList<RiivolutionItem> mItems = new ArrayList<>();

public RiivolutionAdapter(Context context, RiivolutionPatches patches)
{
mContext = context;
mPatches = patches;

int discCount = mPatches.getDiscCount();
for (int i = 0; i < discCount; i++)
{
mItems.add(new RiivolutionItem(i));

int sectionCount = mPatches.getSectionCount(i);
for (int j = 0; j < sectionCount; j++)
{
mItems.add(new RiivolutionItem(i, j));

int optionCount = mPatches.getOptionCount(i, j);
for (int k = 0; k < optionCount; k++)
{
mItems.add(new RiivolutionItem(i, j, k));
}
}
}
}

@NonNull @Override
public RiivolutionViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType)
{
LayoutInflater inflater = LayoutInflater.from(parent.getContext());

switch (viewType)
{
case RiivolutionViewHolder.TYPE_HEADER:
View headerView = inflater.inflate(R.layout.list_item_riivolution_header, parent, false);
return new RiivolutionViewHolder(headerView);
case RiivolutionViewHolder.TYPE_OPTION:
View optionView = inflater.inflate(R.layout.list_item_riivolution_option, parent, false);
return new RiivolutionViewHolder(optionView);
default:
throw new UnsupportedOperationException();
}
}

@Override
public void onBindViewHolder(@NonNull RiivolutionViewHolder holder, int position)
{
holder.bind(mContext, mPatches, mItems.get(position));
}

@Override
public int getItemCount()
{
return mItems.size();
}

@Override
public int getItemViewType(int position)
{
return mItems.get(position).mOptionIndex != -1 ?
RiivolutionViewHolder.TYPE_OPTION : RiivolutionViewHolder.TYPE_HEADER;
}
}
Loading
Oops, something went wrong.

0 comments on commit 96a6d6f

Please sign in to comment.