Core/AchievementManager: Refactor IsApprovedCode and users
This commit is contained in:
1 parent
c0e75f2821
commit
bc4b977e9d
2 files changed
+29
-38
No files matched your search
@@ -12,13 +12,13 @@
|
|||||||
|
|
||||||
#include <rcheevos/include/rc_api_info.h>
|
#include <rcheevos/include/rc_api_info.h>
|
||||||
|
|
||||||
#include "Common/Assert.h"
|
|
||||||
#include "Common/BitUtils.h"
|
#include "Common/BitUtils.h"
|
||||||
#include "Common/CommonPaths.h"
|
#include "Common/CommonPaths.h"
|
||||||
#include "Common/Config/Config.h"
|
#include "Common/Config/Config.h"
|
||||||
#include "Common/FileUtil.h"
|
#include "Common/FileUtil.h"
|
||||||
|
#include "Common/HttpRequest.h"
|
||||||
#include "Common/IOFile.h"
|
#include "Common/IOFile.h"
|
||||||
#include "Common/Image.h"
|
#include "Common/JsonUtil.h"
|
||||||
#include "Common/Logging/Log.h"
|
#include "Common/Logging/Log.h"
|
||||||
#include "Common/ScopeGuard.h"
|
#include "Common/ScopeGuard.h"
|
||||||
#include "Common/StringUtil.h"
|
#include "Common/StringUtil.h"
|
||||||
@@ -33,7 +33,6 @@
|
|||||||
#include "Core/GeckoCode.h"
|
#include "Core/GeckoCode.h"
|
||||||
#include "Core/HW/Memmap.h"
|
#include "Core/HW/Memmap.h"
|
||||||
#include "Core/HW/VideoInterface.h"
|
#include "Core/HW/VideoInterface.h"
|
||||||
#include "Core/Host.h"
|
|
||||||
#include "Core/PatchEngine.h"
|
#include "Core/PatchEngine.h"
|
||||||
#include "Core/PowerPC/MMU.h"
|
#include "Core/PowerPC/MMU.h"
|
||||||
#include "Core/System.h"
|
#include "Core/System.h"
|
||||||
@@ -414,7 +413,7 @@ bool AchievementManager::IsHardcoreModeActive() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
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
|
u16 revision) const
|
||||||
{
|
{
|
||||||
if (codes.empty())
|
if (codes.empty())
|
||||||
@@ -443,7 +442,7 @@ void AchievementManager::FilterApprovedIni(std::vector<T>& codes, const std::str
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
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
|
u16 revision) const
|
||||||
{
|
{
|
||||||
if (!code.enabled)
|
if (!code.enabled)
|
||||||
@@ -470,8 +469,7 @@ bool AchievementManager::ShouldCodeBeActivated(const T& code, const std::string&
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool AchievementManager::IsApprovedCode(const T& code, const std::string& game_id,
|
bool AchievementManager::IsApprovedCode(const T& code, std::string_view game_id, u16 revision) const
|
||||||
u16 revision) const
|
|
||||||
{
|
{
|
||||||
// Approved codes list failed to hash
|
// Approved codes list failed to hash
|
||||||
if (!m_ini_root->is<picojson::value::object>())
|
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,
|
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);
|
FilterApprovedIni(patches, game_id, revision);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AchievementManager::FilterApprovedGeckoCodes(std::vector<Gecko::GeckoCode>& codes,
|
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);
|
FilterApprovedIni(codes, game_id, revision);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AchievementManager::FilterApprovedARCodes(std::vector<ActionReplay::ARCode>& codes,
|
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);
|
FilterApprovedIni(codes, game_id, revision);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AchievementManager::ShouldGeckoCodeBeActivated(const Gecko::GeckoCode& code,
|
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);
|
return ShouldCodeBeActivated(code, game_id, revision);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AchievementManager::ShouldARCodeBeActivated(const ActionReplay::ARCode& code,
|
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);
|
return ShouldCodeBeActivated(code, game_id, revision);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AchievementManager::IsApprovedGeckoCode(const Gecko::GeckoCode& code,
|
bool AchievementManager::IsApprovedGeckoCode(const Gecko::GeckoCode& code, std::string_view game_id,
|
||||||
const std::string& game_id, u16 revision) const
|
u16 revision) const
|
||||||
{
|
{
|
||||||
return IsApprovedCode(code, game_id, revision);
|
return IsApprovedCode(code, game_id, revision);
|
||||||
}
|
}
|
||||||
bool AchievementManager::IsApprovedARCode(const ActionReplay::ARCode& code,
|
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);
|
return IsApprovedCode(code, game_id, revision);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,17 +9,17 @@
|
|||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <map>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <thread>
|
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include <picojson.h>
|
||||||
|
|
||||||
#include <rcheevos/include/rc_api_runtime.h>
|
#include <rcheevos/include/rc_api_runtime.h>
|
||||||
#include <rcheevos/include/rc_api_user.h>
|
#include <rcheevos/include/rc_api_user.h>
|
||||||
#include <rcheevos/include/rc_client.h>
|
#include <rcheevos/include/rc_client.h>
|
||||||
@@ -28,10 +28,7 @@
|
|||||||
|
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
#include "Common/Config/Config.h"
|
#include "Common/Config/Config.h"
|
||||||
#include "Common/Event.h"
|
|
||||||
#include "Common/HookableEvent.h"
|
#include "Common/HookableEvent.h"
|
||||||
#include "Common/HttpRequest.h"
|
|
||||||
#include "Common/JsonUtil.h"
|
|
||||||
#include "Common/Lazy.h"
|
#include "Common/Lazy.h"
|
||||||
#include "Common/WorkQueueThread.h"
|
#include "Common/WorkQueueThread.h"
|
||||||
#include "DiscIO/Volume.h"
|
#include "DiscIO/Volume.h"
|
||||||
@@ -43,7 +40,6 @@
|
|||||||
|
|
||||||
namespace Core
|
namespace Core
|
||||||
{
|
{
|
||||||
class CPUThreadGuard;
|
|
||||||
class System;
|
class System;
|
||||||
} // namespace Core
|
} // namespace Core
|
||||||
|
|
||||||
@@ -77,9 +73,6 @@ public:
|
|||||||
using RichPresence = std::array<char, RP_SIZE>;
|
using RichPresence = std::array<char, RP_SIZE>;
|
||||||
using Badge = VideoCommon::CustomTextureData::ArraySlice::Level;
|
using Badge = VideoCommon::CustomTextureData::ArraySlice::Level;
|
||||||
static constexpr size_t MAX_DISPLAYED_LBOARDS = 4;
|
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_PLAYER_BADGE_FILENAME = "achievements_player.png";
|
||||||
static constexpr std::string_view DEFAULT_GAME_BADGE_FILENAME = "achievements_game.png";
|
static constexpr std::string_view DEFAULT_GAME_BADGE_FILENAME = "achievements_game.png";
|
||||||
@@ -144,19 +137,19 @@ public:
|
|||||||
std::recursive_mutex& GetLock();
|
std::recursive_mutex& GetLock();
|
||||||
bool IsHardcoreModeActive() const;
|
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;
|
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;
|
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;
|
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;
|
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;
|
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;
|
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;
|
u16 revision) const;
|
||||||
|
|
||||||
void SetSpectatorMode();
|
void SetSpectatorMode();
|
||||||
@@ -223,11 +216,11 @@ private:
|
|||||||
void SetHardcoreMode();
|
void SetHardcoreMode();
|
||||||
|
|
||||||
template <typename T>
|
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>
|
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>
|
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 PatchEngine::Patch& patch) const;
|
||||||
Common::SHA1::Digest GetCodeHash(const Gecko::GeckoCode& code) const;
|
Common::SHA1::Digest GetCodeHash(const Gecko::GeckoCode& code) const;
|
||||||
Common::SHA1::Digest GetCodeHash(const ActionReplay::ARCode& code) const;
|
Common::SHA1::Digest GetCodeHash(const ActionReplay::ARCode& code) const;
|
||||||
@@ -326,14 +319,14 @@ public:
|
|||||||
|
|
||||||
constexpr bool IsHardcoreModeActive() { return false; }
|
constexpr bool IsHardcoreModeActive() { return false; }
|
||||||
|
|
||||||
constexpr bool ShouldGeckoCodeBeActivated(const Gecko::GeckoCode& code,
|
constexpr bool ShouldGeckoCodeBeActivated(const Gecko::GeckoCode& code, std::string_view game_id,
|
||||||
const std::string& game_id, u16 revision)
|
u16 revision)
|
||||||
{
|
{
|
||||||
return code.enabled;
|
return code.enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr bool ShouldARCodeBeActivated(const ActionReplay::ARCode& code,
|
constexpr bool ShouldARCodeBeActivated(const ActionReplay::ARCode& code, std::string_view game_id,
|
||||||
const std::string& game_id, u16 revision)
|
u16 revision)
|
||||||
{
|
{
|
||||||
return code.enabled;
|
return code.enabled;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user