Disable cheats in hardcore mode

RetroAchievements does not allow cheats such as Action Replay or Gecko in hardcore mode, for fairness.
This commit is contained in:
LillyJadeKatrin 2023-06-07 21:53:38 -04:00
commit 3aebbbb3e7
17 changed files with 105 additions and 9 deletions

View file

@ -114,7 +114,7 @@ struct ARAddr
// AR Remote Functions
void ApplyCodes(std::span<const ARCode> codes)
{
if (!Config::Get(Config::MAIN_ENABLE_CHEATS))
if (!Config::AreCheatsEnabled())
return;
std::lock_guard guard(s_lock);
@ -143,7 +143,7 @@ void UpdateSyncedCodes(std::span<const ARCode> codes)
std::vector<ARCode> ApplyAndReturnCodes(std::span<const ARCode> codes)
{
if (Config::Get(Config::MAIN_ENABLE_CHEATS))
if (Config::AreCheatsEnabled())
{
std::lock_guard guard(s_lock);
s_disable_logging = false;
@ -158,7 +158,7 @@ std::vector<ARCode> ApplyAndReturnCodes(std::span<const ARCode> codes)
void AddCode(ARCode code)
{
if (!Config::Get(Config::MAIN_ENABLE_CHEATS))
if (!Config::AreCheatsEnabled())
return;
if (code.enabled)
@ -990,7 +990,7 @@ static bool RunCodeLocked(const Core::CPUThreadGuard& guard, const ARCode& arcod
void RunAllActive(const Core::CPUThreadGuard& cpu_guard)
{
if (!Config::Get(Config::MAIN_ENABLE_CHEATS))
if (!Config::AreCheatsEnabled())
return;
// If the mutex is idle then acquiring it should be cheap, fast mutexes

View file

@ -16,6 +16,7 @@
#include "Common/BitUtils.h"
#include "Common/StringUtil.h"
#include "Core/Config/AchievementSettings.h"
#include "Core/Core.h"
#include "Core/HW/Memmap.h"
#include "Core/PowerPC/MMU.h"
@ -206,6 +207,10 @@ Cheats::NewSearch(const Core::CPUThreadGuard& guard,
PowerPC::RequestedAddressSpace address_space, bool aligned,
const std::function<bool(const T& value)>& validator)
{
#ifdef USE_RETRO_ACHIEVEMENTS
if (Config::Get(Config::RA_HARDCORE_ENABLED))
return Cheats::SearchErrorCode::DisabledInHardcoreMode;
#endif // USE_RETRO_ACHIEVEMENTS
const u32 data_size = sizeof(T);
std::vector<Cheats::SearchResult<T>> results;
Cheats::SearchErrorCode error_code = Cheats::SearchErrorCode::Success;
@ -269,6 +274,10 @@ Cheats::NextSearch(const Core::CPUThreadGuard& guard,
PowerPC::RequestedAddressSpace address_space,
const std::function<bool(const T& new_value, const T& old_value)>& validator)
{
#ifdef USE_RETRO_ACHIEVEMENTS
if (Config::Get(Config::RA_HARDCORE_ENABLED))
return Cheats::SearchErrorCode::DisabledInHardcoreMode;
#endif // USE_RETRO_ACHIEVEMENTS
std::vector<Cheats::SearchResult<T>> results;
Cheats::SearchErrorCode error_code = Cheats::SearchErrorCode::Success;
Core::RunAsCPUThread([&] {
@ -444,6 +453,10 @@ MakeCompareFunctionForLastValue(Cheats::CompareType op)
template <typename T>
Cheats::SearchErrorCode Cheats::CheatSearchSession<T>::RunSearch(const Core::CPUThreadGuard& guard)
{
#ifdef USE_RETRO_ACHIEVEMENTS
if (Config::Get(Config::RA_HARDCORE_ENABLED))
return Cheats::SearchErrorCode::DisabledInHardcoreMode;
#endif // USE_RETRO_ACHIEVEMENTS
Common::Result<SearchErrorCode, std::vector<SearchResult<T>>> result =
Cheats::SearchErrorCode::InvalidParameters;
if (m_filter_type == FilterType::CompareAgainstSpecificValue)

View file

@ -99,6 +99,11 @@ enum class SearchErrorCode
// This is returned if PowerPC::RequestedAddressSpace::Virtual is given but the MSR.DR flag is
// currently off in the emulated game.
VirtualAddressesCurrentlyNotAccessible,
#ifdef USE_RETRO_ACHIEVEMENTS
// Cheats and memory reading are disabled in RetroAchievements hardcore mode.
DisabledInHardcoreMode,
#endif // USE_RETRO_ACHIEVEMENTS
};
// Returns the corresponding DataType enum for the value currently held by the given SearchValue.

View file

@ -18,6 +18,7 @@
#include "Common/MathUtil.h"
#include "Common/StringUtil.h"
#include "Common/Version.h"
#include "Core/Config/AchievementSettings.h"
#include "Core/Config/DefaultLocale.h"
#include "Core/HW/EXI/EXI.h"
#include "Core/HW/EXI/EXI_Device.h"
@ -739,6 +740,15 @@ bool IsDefaultGCIFolderPathConfigured(ExpansionInterface::Slot slot)
return Config::Get(GetInfoForGCIPath(slot)).empty();
}
bool AreCheatsEnabled()
{
#ifdef USE_RETRO_ACHIEVEMENTS
return Config::Get(::Config::MAIN_ENABLE_CHEATS) && !::Config::Get(::Config::RA_HARDCORE_ENABLED);
#else // USE_RETRO_ACHIEVEMENTS
return Config::Get(::Config::MAIN_ENABLE_CHEATS);
#endif // USE_RETRO_ACHIEVEMENTS
}
bool IsDebuggingEnabled()
{
#ifdef USE_RETRO_ACHIEVEMENTS

View file

@ -378,5 +378,6 @@ std::string GetGCIFolderPath(ExpansionInterface::Slot slot, std::optional<DiscIO
std::string GetGCIFolderPath(std::string configured_folder, ExpansionInterface::Slot slot,
std::optional<DiscIO::Region> region);
bool IsDefaultGCIFolderPathConfigured(ExpansionInterface::Slot slot);
bool AreCheatsEnabled();
bool IsDebuggingEnabled();
} // namespace Config

View file

@ -71,7 +71,7 @@ void SetActiveCodes(std::span<const GeckoCode> gcodes)
std::lock_guard lk(s_active_codes_lock);
s_active_codes.clear();
if (Config::Get(Config::MAIN_ENABLE_CHEATS))
if (Config::AreCheatsEnabled())
{
s_active_codes.reserve(gcodes.size());
std::copy_if(gcodes.begin(), gcodes.end(), std::back_inserter(s_active_codes),
@ -103,7 +103,7 @@ std::vector<GeckoCode> SetAndReturnActiveCodes(std::span<const GeckoCode> gcodes
std::lock_guard lk(s_active_codes_lock);
s_active_codes.clear();
if (Config::Get(Config::MAIN_ENABLE_CHEATS))
if (Config::AreCheatsEnabled())
{
s_active_codes.reserve(gcodes.size());
std::copy_if(gcodes.begin(), gcodes.end(), std::back_inserter(s_active_codes),
@ -238,7 +238,7 @@ void Shutdown()
void RunCodeHandler(const Core::CPUThreadGuard& guard)
{
if (!Config::Get(Config::MAIN_ENABLE_CHEATS))
if (!Config::AreCheatsEnabled())
return;
// NOTE: Need to release the lock because of GUI deadlocks with PanicAlert in HostWrite_*

View file

@ -90,7 +90,7 @@ void PatchFixedFunctions(Core::System& system)
// HLE jump to loader (homebrew). Disabled when Gecko is active as it interferes with the code
// handler
if (!Config::Get(Config::MAIN_ENABLE_CHEATS))
if (!Config::AreCheatsEnabled())
{
Patch(system, 0x80001800, "HBReload");
auto& memory = system.GetMemory();

View file

@ -1356,7 +1356,7 @@ bool NetPlayServer::SetupNetSettings()
// Copy all relevant settings
settings.cpu_thread = Config::Get(Config::MAIN_CPU_THREAD);
settings.cpu_core = Config::Get(Config::MAIN_CPU_CORE);
settings.enable_cheats = Config::Get(Config::MAIN_ENABLE_CHEATS);
settings.enable_cheats = Config::AreCheatsEnabled();
settings.selected_language = Config::Get(Config::MAIN_GC_LANGUAGE);
settings.override_region_settings = Config::Get(Config::MAIN_OVERRIDE_REGION_SETTINGS);
settings.dsp_hle = Config::Get(Config::MAIN_DSP_HLE);