From e885c65b6cb518eb14d697d5b724f2cf070dda11 Mon Sep 17 00:00:00 2001 From: scawful Date: Sat, 10 Aug 2024 21:32:16 -0400 Subject: [PATCH] add yaze_check_version and core::CheckVersion --- src/app/core/common.cc | 12 ++++++++++++ src/app/core/common.h | 2 ++ src/yaze.cc | 13 +++++++++++++ src/yaze.h | 2 ++ 4 files changed, 29 insertions(+) diff --git a/src/app/core/common.cc b/src/app/core/common.cc index d31d70f0..2cf0dce7 100644 --- a/src/app/core/common.cc +++ b/src/app/core/common.cc @@ -13,6 +13,7 @@ #include #include +#include "absl/status/statusor.h" #include "absl/strings/str_format.h" #include "imgui/imgui.h" @@ -322,6 +323,17 @@ void ApplyBpsPatch(const std::vector &source, } } +absl::StatusOr CheckVersion(const char* version) { + std::string version_string = version; + if (version_string != kYazeVersion) { + std::string message = absl::StrFormat( + "Yaze version mismatch: expected %s, got %s", kYazeVersion, + version_string.c_str()); + return absl::InvalidArgumentError(message); + } + return version_string; +} + } // namespace core } // namespace app } // namespace yaze diff --git a/src/app/core/common.h b/src/app/core/common.h index 4530a66c..e977f360 100644 --- a/src/app/core/common.h +++ b/src/app/core/common.h @@ -271,6 +271,8 @@ void ApplyBpsPatch(const std::vector &source, const std::vector &patch, std::vector &target); +absl::StatusOr CheckVersion(const char *version); + } // namespace core } // namespace app } // namespace yaze diff --git a/src/yaze.cc b/src/yaze.cc index 5f43380b..336b64c1 100644 --- a/src/yaze.cc +++ b/src/yaze.cc @@ -1,8 +1,21 @@ #include "yaze.h" +#include + #include "app/rom.h" #include "app/zelda3/overworld/overworld.h" +void yaze_check_version(const char* version) { + auto version_check = yaze::app::core::CheckVersion(version); + if (!version_check.ok()) { + // Print the error message to the console for a pure C interface. + printf("%s\n", version_check.status().message().c_str()); + // Exit the program if the version check fails. + exit(1); + } + return; +} + void yaze_init(yaze_flags* flags) { if (flags == nullptr) { return; diff --git a/src/yaze.h b/src/yaze.h index 09201e8e..5be798c0 100644 --- a/src/yaze.h +++ b/src/yaze.h @@ -64,6 +64,8 @@ struct yaze_flags { z3_rom* rom; }; +void yaze_check_version(const char* version); + /** * @brief Initialize the Yaze library. *