Skip to content

Commit

Permalink
Merge pull request #13035 from retroNUC/cheevo-hash
Browse files Browse the repository at this point in the history
Add generation of rcheevos hash as an option in DolphinTool
  • Loading branch information
Tilka authored Sep 15, 2024
2 parents 5fe9e2f + a74b2a4 commit af92168
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ Options:
Path to disc image FILE.
-a ALGORITHM, --algorithm=ALGORITHM
Optional. Compute and print the digest using the
selected algorithm, then exit. [crc32|md5|sha1]
selected algorithm, then exit. [crc32|md5|sha1|rchash]
```

```
Expand Down
16 changes: 16 additions & 0 deletions Source/Core/Core/AchievementManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,22 @@ void AchievementManager::SetBackgroundExecutionAllowed(bool allowed)
DoIdle();
}

std::string AchievementManager::CalculateHash(const std::string& file_path)
{
char hash_result[33] = "0";
rc_hash_filereader volume_reader{
.open = &AchievementManager::FilereaderOpenByFilepath,
.seek = &AchievementManager::FilereaderSeek,
.tell = &AchievementManager::FilereaderTell,
.read = &AchievementManager::FilereaderRead,
.close = &AchievementManager::FilereaderClose,
};
rc_hash_init_custom_filereader(&volume_reader);
rc_hash_generate_from_file(hash_result, RC_CONSOLE_GAMECUBE, file_path.c_str());

return std::string(hash_result);
}

void AchievementManager::FetchPlayerBadge()
{
FetchBadge(&m_player_badge, RC_IMAGE_TYPE_USER,
Expand Down
2 changes: 2 additions & 0 deletions Source/Core/Core/AchievementManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ class AchievementManager
bool IsGameLoaded() const;
void SetBackgroundExecutionAllowed(bool allowed);

static std::string CalculateHash(const std::string& file_path);

void FetchPlayerBadge();
void FetchGameBadges();

Expand Down
1 change: 1 addition & 0 deletions Source/Core/DolphinTool/DolphinTool.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<Import Project="$(ExternalsDir)liblzma\exports.props" />
<Import Project="$(ExternalsDir)mbedtls\exports.props" />
<Import Project="$(ExternalsDir)picojson\exports.props" />
<Import Project="$(ExternalsDir)rcheevos\exports.props" />
<Import Project="$(ExternalsDir)zstd\exports.props" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
19 changes: 17 additions & 2 deletions Source/Core/DolphinTool/VerifyCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <fmt/ostream.h>

#include "Common/StringUtil.h"
#include "Core/AchievementManager.h"
#include "DiscIO/Volume.h"
#include "DiscIO/VolumeVerifier.h"
#include "UICommon/UICommon.h"
Expand Down Expand Up @@ -97,7 +98,7 @@ int VerifyCommand(const std::vector<std::string>& args)
.action("store")
.help("Optional. Compute and print the digest using the selected algorithm, then exit. "
"[%choices]")
.choices({"crc32", "md5", "sha1"});
.choices({"crc32", "md5", "sha1", "rchash"});

const optparse::Values& options = parser.parse_args(args);

Expand All @@ -114,6 +115,9 @@ int VerifyCommand(const std::vector<std::string>& args)
}
const std::string& input_file_path = options["input"];

bool rc_hash_calculate = false;
std::string rc_hash_result = "0";

DiscIO::Hashes<bool> hashes_to_calculate{};
const bool algorithm_is_set = options.is_set("algorithm");
if (!algorithm_is_set)
Expand All @@ -129,9 +133,12 @@ int VerifyCommand(const std::vector<std::string>& args)
hashes_to_calculate.md5 = true;
else if (algorithm == "sha1")
hashes_to_calculate.sha1 = true;
else if (algorithm == "rchash")
rc_hash_calculate = true;
}

if (!hashes_to_calculate.crc32 && !hashes_to_calculate.md5 && !hashes_to_calculate.sha1)
if (!hashes_to_calculate.crc32 && !hashes_to_calculate.md5 && !hashes_to_calculate.sha1 &&
!rc_hash_calculate)
{
// optparse should protect from this
fmt::print(std::cerr, "Error: No algorithms selected for the operation\n");
Expand All @@ -156,6 +163,12 @@ int VerifyCommand(const std::vector<std::string>& args)
verifier.Finish();
const DiscIO::VolumeVerifier::Result& result = verifier.GetResult();

// Calculate rcheevos hash
if (rc_hash_calculate)
{
rc_hash_result = AchievementManager::CalculateHash(input_file_path);
}

// Print the report
if (!algorithm_is_set)
{
Expand All @@ -169,6 +182,8 @@ int VerifyCommand(const std::vector<std::string>& args)
fmt::print(std::cout, "{}\n", HashToHexString(result.hashes.md5));
else if (hashes_to_calculate.sha1 && !result.hashes.sha1.empty())
fmt::print(std::cout, "{}\n", HashToHexString(result.hashes.sha1));
else if (rc_hash_calculate)
fmt::print(std::cout, "{}\n", rc_hash_result);
else
{
fmt::print(std::cerr, "Error: No hash computed\n");
Expand Down

0 comments on commit af92168

Please sign in to comment.