Core/AchievementManager: Refactor IsApprovedCode and users

This commit is contained in:
Sintendo
2026-01-24 17:42:17 +01:00
parent c0e75f2821
commit bc4b977e9d
2 changed files with 29 additions and 38 deletions

View File

@@ -12,13 +12,13 @@
#include <rcheevos/include/rc_api_info.h>
#include "Common/Assert.h"
#include "Common/BitUtils.h"
#include "Common/CommonPaths.h"
#include "Common/Config/Config.h"
#include "Common/FileUtil.h"
#include "Common/HttpRequest.h"
#include "Common/IOFile.h"
#include "Common/Image.h"
#include "Common/JsonUtil.h"
#include "Common/Logging/Log.h"
#include "Common/ScopeGuard.h"
#include "Common/StringUtil.h"
@@ -33,7 +33,6 @@
#include "Core/GeckoCode.h"
#include "Core/HW/Memmap.h"
#include "Core/HW/VideoInterface.h"
#include "Core/Host.h"
#include "Core/PatchEngine.h"
#include "Core/PowerPC/MMU.h"
#include "Core/System.h"
@@ -414,7 +413,7 @@ bool AchievementManager::IsHardcoreModeActive() const
}
template <typename T>
void AchievementManager::FilterApprovedIni(std::vector<T>& codes, const std::string& game_id,
void AchievementManager::FilterApprovedIni(std::vector<T>& codes, std::string_view game_id,
u16 revision) const
{
if (codes.empty())
@@ -443,7 +442,7 @@ void AchievementManager::FilterApprovedIni(std::vector<T>& codes, const std::str
}
template <typename T>
bool AchievementManager::ShouldCodeBeActivated(const T& code, const std::string& game_id,
bool AchievementManager::ShouldCodeBeActivated(const T& code, std::string_view game_id,
u16 revision) const
{
if (!code.enabled)
@@ -470,8 +469,7 @@ bool AchievementManager::ShouldCodeBeActivated(const T& code, const std::string&
}
template <typename T>
bool AchievementManager::IsApprovedCode(const T& code, const std::string& game_id,
u16 revision) const
bool AchievementManager::IsApprovedCode(const T& code, std::string_view game_id, u16 revision) const
{
// Approved codes list failed to hash
if (!m_ini_root->is<picojson::value::object>())
@@ -536,42 +534,42 @@ Common::SHA1::Digest AchievementManager::GetCodeHash(const ActionReplay::ARCode&
}
void AchievementManager::FilterApprovedPatches(std::vector<PatchEngine::Patch>& patches,
const std::string& game_id, u16 revision) const
std::string_view game_id, u16 revision) const
{
FilterApprovedIni(patches, game_id, revision);
}
void AchievementManager::FilterApprovedGeckoCodes(std::vector<Gecko::GeckoCode>& codes,
const std::string& game_id, u16 revision) const
std::string_view game_id, u16 revision) const
{
FilterApprovedIni(codes, game_id, revision);
}
void AchievementManager::FilterApprovedARCodes(std::vector<ActionReplay::ARCode>& codes,
const std::string& game_id, u16 revision) const
std::string_view game_id, u16 revision) const
{
FilterApprovedIni(codes, game_id, revision);
}
bool AchievementManager::ShouldGeckoCodeBeActivated(const Gecko::GeckoCode& code,
const std::string& game_id, u16 revision) const
std::string_view game_id, u16 revision) const
{
return ShouldCodeBeActivated(code, game_id, revision);
}
bool AchievementManager::ShouldARCodeBeActivated(const ActionReplay::ARCode& code,
const std::string& game_id, u16 revision) const
std::string_view game_id, u16 revision) const
{
return ShouldCodeBeActivated(code, game_id, revision);
}
bool AchievementManager::IsApprovedGeckoCode(const Gecko::GeckoCode& code,
const std::string& game_id, u16 revision) const
bool AchievementManager::IsApprovedGeckoCode(const Gecko::GeckoCode& code, std::string_view game_id,
u16 revision) const
{
return IsApprovedCode(code, game_id, revision);
}
bool AchievementManager::IsApprovedARCode(const ActionReplay::ARCode& code,
const std::string& game_id, u16 revision) const
std::string_view game_id, u16 revision) const
{
return IsApprovedCode(code, game_id, revision);
}

View File

@@ -9,17 +9,17 @@
#include <chrono>
#include <ctime>
#include <functional>
#include <map>
#include <memory>
#include <mutex>
#include <set>
#include <string>
#include <string_view>
#include <thread>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <picojson.h>
#include <rcheevos/include/rc_api_runtime.h>
#include <rcheevos/include/rc_api_user.h>
#include <rcheevos/include/rc_client.h>
@@ -28,10 +28,7 @@
#include "Common/CommonTypes.h"
#include "Common/Config/Config.h"
#include "Common/Event.h"
#include "Common/HookableEvent.h"
#include "Common/HttpRequest.h"
#include "Common/JsonUtil.h"
#include "Common/Lazy.h"
#include "Common/WorkQueueThread.h"
#include "DiscIO/Volume.h"
@@ -43,7 +40,6 @@
namespace Core
{
class CPUThreadGuard;
class System;
} // namespace Core
@@ -77,9 +73,6 @@ public:
using RichPresence = std::array<char, RP_SIZE>;
using Badge = VideoCommon::CustomTextureData::ArraySlice::Level;
static constexpr size_t MAX_DISPLAYED_LBOARDS = 4;
// This is hardcoded to 24MiB because rcheevos currently hardcodes it to 24MiB.
static constexpr u32 MEM1_SIZE = 0x01800000;
static constexpr u32 MEM2_START = 0x10000000;
static constexpr std::string_view DEFAULT_PLAYER_BADGE_FILENAME = "achievements_player.png";
static constexpr std::string_view DEFAULT_GAME_BADGE_FILENAME = "achievements_game.png";
@@ -144,19 +137,19 @@ public:
std::recursive_mutex& GetLock();
bool IsHardcoreModeActive() const;
void FilterApprovedPatches(std::vector<PatchEngine::Patch>& patches, const std::string& game_id,
void FilterApprovedPatches(std::vector<PatchEngine::Patch>& patches, std::string_view game_id,
u16 revision) const;
void FilterApprovedGeckoCodes(std::vector<Gecko::GeckoCode>& codes, const std::string& game_id,
void FilterApprovedGeckoCodes(std::vector<Gecko::GeckoCode>& codes, std::string_view game_id,
u16 revision) const;
void FilterApprovedARCodes(std::vector<ActionReplay::ARCode>& codes, const std::string& game_id,
void FilterApprovedARCodes(std::vector<ActionReplay::ARCode>& codes, std::string_view game_id,
u16 revision) const;
bool ShouldGeckoCodeBeActivated(const Gecko::GeckoCode& code, const std::string& game_id,
bool ShouldGeckoCodeBeActivated(const Gecko::GeckoCode& code, std::string_view game_id,
u16 revision) const;
bool ShouldARCodeBeActivated(const ActionReplay::ARCode& code, const std::string& game_id,
bool ShouldARCodeBeActivated(const ActionReplay::ARCode& code, std::string_view game_id,
u16 revision) const;
bool IsApprovedGeckoCode(const Gecko::GeckoCode& code, const std::string& game_id,
bool IsApprovedGeckoCode(const Gecko::GeckoCode& code, std::string_view game_id,
u16 revision) const;
bool IsApprovedARCode(const ActionReplay::ARCode& code, const std::string& game_id,
bool IsApprovedARCode(const ActionReplay::ARCode& code, std::string_view game_id,
u16 revision) const;
void SetSpectatorMode();
@@ -223,11 +216,11 @@ private:
void SetHardcoreMode();
template <typename T>
void FilterApprovedIni(std::vector<T>& codes, const std::string& game_id, u16 revision) const;
void FilterApprovedIni(std::vector<T>& codes, std::string_view game_id, u16 revision) const;
template <typename T>
bool ShouldCodeBeActivated(const T& code, const std::string& game_id, u16 revision) const;
bool ShouldCodeBeActivated(const T& code, std::string_view game_id, u16 revision) const;
template <typename T>
bool IsApprovedCode(const T& code, const std::string& game_id, u16 revision) const;
bool IsApprovedCode(const T& code, std::string_view game_id, u16 revision) const;
Common::SHA1::Digest GetCodeHash(const PatchEngine::Patch& patch) const;
Common::SHA1::Digest GetCodeHash(const Gecko::GeckoCode& code) const;
Common::SHA1::Digest GetCodeHash(const ActionReplay::ARCode& code) const;
@@ -326,14 +319,14 @@ public:
constexpr bool IsHardcoreModeActive() { return false; }
constexpr bool ShouldGeckoCodeBeActivated(const Gecko::GeckoCode& code,
const std::string& game_id, u16 revision)
constexpr bool ShouldGeckoCodeBeActivated(const Gecko::GeckoCode& code, std::string_view game_id,
u16 revision)
{
return code.enabled;
}
constexpr bool ShouldARCodeBeActivated(const ActionReplay::ARCode& code,
const std::string& game_id, u16 revision)
constexpr bool ShouldARCodeBeActivated(const ActionReplay::ARCode& code, std::string_view game_id,
u16 revision)
{
return code.enabled;
}