mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2024-11-14 13:27:45 -07:00
Add Gecko Code Whitelist Approval
This commit is contained in:
parent
dc49d8cd6b
commit
b3c5dc5fb9
@ -28,6 +28,7 @@
|
||||
#include "Core/Config/FreeLookSettings.h"
|
||||
#include "Core/Config/MainSettings.h"
|
||||
#include "Core/Core.h"
|
||||
#include "Core/GeckoCode.h"
|
||||
#include "Core/HW/Memmap.h"
|
||||
#include "Core/HW/VideoInterface.h"
|
||||
#include "Core/PatchEngine.h"
|
||||
@ -461,12 +462,36 @@ Common::SHA1::Digest AchievementManager::GetCodeHash(const PatchEngine::Patch& p
|
||||
return context->Finish();
|
||||
}
|
||||
|
||||
Common::SHA1::Digest AchievementManager::GetCodeHash(const Gecko::GeckoCode& code) const
|
||||
{
|
||||
auto context = Common::SHA1::CreateContext();
|
||||
context->Update(Common::BitCastToArray<u8>(static_cast<u64>(code.codes.size())));
|
||||
for (const auto& entry : code.codes)
|
||||
{
|
||||
context->Update(Common::BitCastToArray<u8>(entry.address));
|
||||
context->Update(Common::BitCastToArray<u8>(entry.data));
|
||||
}
|
||||
return context->Finish();
|
||||
}
|
||||
|
||||
void AchievementManager::FilterApprovedPatches(std::vector<PatchEngine::Patch>& patches,
|
||||
const std::string& game_ini_id) const
|
||||
{
|
||||
FilterApprovedIni(patches, game_ini_id);
|
||||
}
|
||||
|
||||
void AchievementManager::FilterApprovedGeckoCodes(std::vector<Gecko::GeckoCode>& codes,
|
||||
const std::string& game_ini_id) const
|
||||
{
|
||||
FilterApprovedIni(codes, game_ini_id);
|
||||
}
|
||||
|
||||
bool AchievementManager::CheckApprovedGeckoCode(const Gecko::GeckoCode& code,
|
||||
const std::string& game_ini_id) const
|
||||
{
|
||||
return CheckApprovedCode(code, game_ini_id);
|
||||
}
|
||||
|
||||
void AchievementManager::SetSpectatorMode()
|
||||
{
|
||||
rc_client_set_spectator_mode_enabled(m_client, Config::Get(Config::RA_SPECTATOR_ENABLED));
|
||||
|
@ -45,6 +45,11 @@ namespace PatchEngine
|
||||
struct Patch;
|
||||
} // namespace PatchEngine
|
||||
|
||||
namespace Gecko
|
||||
{
|
||||
class GeckoCode;
|
||||
} // namespace Gecko
|
||||
|
||||
class AchievementManager
|
||||
{
|
||||
public:
|
||||
@ -125,8 +130,13 @@ public:
|
||||
void SetHardcoreMode();
|
||||
bool IsHardcoreModeActive() const;
|
||||
void SetGameIniId(const std::string& game_ini_id) { m_game_ini_id = game_ini_id; }
|
||||
|
||||
void FilterApprovedPatches(std::vector<PatchEngine::Patch>& patches,
|
||||
const std::string& game_ini_id) const;
|
||||
void FilterApprovedGeckoCodes(std::vector<Gecko::GeckoCode>& codes,
|
||||
const std::string& game_ini_id) const;
|
||||
bool CheckApprovedGeckoCode(const Gecko::GeckoCode& code, const std::string& game_ini_id) const;
|
||||
|
||||
void SetSpectatorMode();
|
||||
std::string_view GetPlayerDisplayName() const;
|
||||
u32 GetPlayerScore() const;
|
||||
@ -186,6 +196,7 @@ private:
|
||||
template <typename T>
|
||||
bool CheckApprovedCode(const T& code, const std::string& game_ini_id) const;
|
||||
Common::SHA1::Digest GetCodeHash(const PatchEngine::Patch& patch) const;
|
||||
Common::SHA1::Digest GetCodeHash(const Gecko::GeckoCode& code) const;
|
||||
|
||||
static void LeaderboardEntriesCallback(int result, const char* error_message,
|
||||
rc_client_leaderboard_entry_list_t* list,
|
||||
@ -271,6 +282,12 @@ public:
|
||||
|
||||
constexpr bool IsHardcoreModeActive() { return false; }
|
||||
|
||||
constexpr bool CheckApprovedGeckoCode(const Gecko::GeckoCode& code,
|
||||
const std::string& game_ini_id)
|
||||
{
|
||||
return true;
|
||||
};
|
||||
|
||||
constexpr void LoadGame(const std::string&, const DiscIO::Volume*) {}
|
||||
|
||||
constexpr void SetBackgroundExecutionAllowed(bool allowed) {}
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "Common/Config/Config.h"
|
||||
#include "Common/FileUtil.h"
|
||||
|
||||
#include "Core/AchievementManager.h"
|
||||
#include "Core/Config/MainSettings.h"
|
||||
#include "Core/Core.h"
|
||||
#include "Core/Host.h"
|
||||
@ -49,7 +50,7 @@ static std::vector<GeckoCode> s_active_codes;
|
||||
static std::vector<GeckoCode> s_synced_codes;
|
||||
static std::mutex s_active_codes_lock;
|
||||
|
||||
void SetActiveCodes(std::span<const GeckoCode> gcodes)
|
||||
void SetActiveCodes(std::span<const GeckoCode> gcodes, const std::string& game_id)
|
||||
{
|
||||
std::lock_guard lk(s_active_codes_lock);
|
||||
|
||||
@ -57,8 +58,12 @@ void SetActiveCodes(std::span<const GeckoCode> gcodes)
|
||||
if (Config::AreCheatsEnabled())
|
||||
{
|
||||
s_active_codes.reserve(gcodes.size());
|
||||
|
||||
std::copy_if(gcodes.begin(), gcodes.end(), std::back_inserter(s_active_codes),
|
||||
[](const GeckoCode& code) { return code.enabled; });
|
||||
[&game_id](const GeckoCode& code) {
|
||||
return code.enabled &&
|
||||
AchievementManager::GetInstance().CheckApprovedGeckoCode(code, game_id);
|
||||
});
|
||||
}
|
||||
s_active_codes.shrink_to_fit();
|
||||
|
||||
|
@ -60,7 +60,7 @@ constexpr u32 HLE_TRAMPOLINE_ADDRESS = INSTALLER_END_ADDRESS - 4;
|
||||
// preserve the emulation performance.
|
||||
constexpr u32 MAGIC_GAMEID = 0xD01F1BAD;
|
||||
|
||||
void SetActiveCodes(std::span<const GeckoCode> gcodes);
|
||||
void SetActiveCodes(std::span<const GeckoCode> gcodes, const std::string& game_id);
|
||||
void SetSyncedCodesAsActive();
|
||||
void UpdateSyncedCodes(std::span<const GeckoCode> gcodes);
|
||||
std::vector<GeckoCode> SetAndReturnActiveCodes(std::span<const GeckoCode> gcodes);
|
||||
|
@ -2070,13 +2070,18 @@ bool NetPlayServer::SyncCodes()
|
||||
}
|
||||
// Sync Gecko Codes
|
||||
{
|
||||
std::vector<Gecko::GeckoCode> codes = Gecko::LoadCodes(globalIni, localIni);
|
||||
|
||||
#ifdef USE_RETRO_ACHIEVEMENTS
|
||||
AchievementManager::GetInstance().FilterApprovedGeckoCodes(codes, game_id);
|
||||
#endif // USE_RETRO_ACHIEVEMENTS
|
||||
|
||||
// Create a Gecko Code Vector with just the active codes
|
||||
std::vector<Gecko::GeckoCode> s_active_codes =
|
||||
Gecko::SetAndReturnActiveCodes(Gecko::LoadCodes(globalIni, localIni));
|
||||
std::vector<Gecko::GeckoCode> active_codes = Gecko::SetAndReturnActiveCodes(codes);
|
||||
|
||||
// Determine Codelist Size
|
||||
u16 codelines = 0;
|
||||
for (const Gecko::GeckoCode& active_code : s_active_codes)
|
||||
for (const Gecko::GeckoCode& active_code : active_codes)
|
||||
{
|
||||
INFO_LOG_FMT(NETPLAY, "Indexing {}", active_code.name);
|
||||
for (const Gecko::GeckoCode::Code& code : active_code.codes)
|
||||
@ -2104,7 +2109,7 @@ bool NetPlayServer::SyncCodes()
|
||||
pac << MessageID::SyncCodes;
|
||||
pac << SyncCodeID::GeckoData;
|
||||
// Iterate through the active code vector and send each codeline
|
||||
for (const Gecko::GeckoCode& active_code : s_active_codes)
|
||||
for (const Gecko::GeckoCode& active_code : active_codes)
|
||||
{
|
||||
INFO_LOG_FMT(NETPLAY, "Sending {}", active_code.name);
|
||||
for (const Gecko::GeckoCode::Code& code : active_code.codes)
|
||||
|
@ -197,7 +197,7 @@ void LoadPatches()
|
||||
}
|
||||
else
|
||||
{
|
||||
Gecko::SetActiveCodes(Gecko::LoadCodes(globalIni, localIni));
|
||||
Gecko::SetActiveCodes(Gecko::LoadCodes(globalIni, localIni), sconfig.GetGameID());
|
||||
ActionReplay::LoadAndApplyCodes(globalIni, localIni);
|
||||
}
|
||||
}
|
||||
|
@ -202,7 +202,7 @@ void GeckoCodeWidget::OnItemChanged(QListWidgetItem* item)
|
||||
m_gecko_codes[index].enabled = (item->checkState() == Qt::Checked);
|
||||
|
||||
if (!m_restart_required)
|
||||
Gecko::SetActiveCodes(m_gecko_codes);
|
||||
Gecko::SetActiveCodes(m_gecko_codes, m_game_id);
|
||||
|
||||
SaveCodes();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user