diff --git a/include/autohooks.hpp b/include/AutoHooks.hpp similarity index 85% rename from include/autohooks.hpp rename to include/AutoHooks.hpp index 7fe1fcc..3b75dd2 100644 --- a/include/autohooks.hpp +++ b/include/AutoHooks.hpp @@ -3,32 +3,30 @@ #include "beatsaber-hook/shared/utils/hooking.hpp" #include -class AutoHooks { -private: - inline static std::vector installFuncs; +namespace AutoHooks { + inline std::vector installFuncs; -public: - static void AddInstallFunc(void (*installFunc)()) { + inline void AddInstallFunc(void (*installFunc)()) { installFuncs.push_back(installFunc); } - static inline void InstallHooks() { + inline void InstallHooks() { for (auto& func : installFuncs) func(); } -}; -template -concept has_metadata = requires() { - { ::il2cpp_utils::il2cpp_type_check::MetadataGetter::methodInfo() } -> std::same_as; -}; + template + concept has_metadata = requires() { + { ::il2cpp_utils::il2cpp_type_check::MetadataGetter::methodInfo() } -> std::same_as; + }; -template -requires(has_metadata) -using Metadata = ::il2cpp_utils::il2cpp_type_check::MetadataGetter; + template + requires(has_metadata) + using Metadata = ::il2cpp_utils::il2cpp_type_check::MetadataGetter; -/// @brief checks whether the function is match hookable, which requires the function to be at least 5 (5 * 4 = 20 bytes) instructions and not have an address of 0 (abstract/virtual funcs) -template -concept match_hookable = has_metadata && Metadata::size >= (0x5 * sizeof(int32_t)) && Metadata::addrs != 0xffffffff; + /// @brief checks whether the function is match hookable, which requires the function to be at least 5 (5 * 4 = 20 bytes) instructions and not have an address of 0 (abstract/virtual funcs) + template + concept match_hookable = has_metadata && Metadata::size >= (0x5 * sizeof(int32_t)) && Metadata::addrs != 0xffffffff; +} #define HOOK_AUTO_INSTALL_ORIG(name_) \ struct Auto_Hook_##name_ { \ @@ -53,7 +51,7 @@ concept match_hookable = has_metadata && Metadata::size >= (0x5 * si #define MAKE_AUTO_HOOK_MATCH(name_, mPtr, retval, ...) \ struct Hook_##name_ { \ using funcType = retval (*)(__VA_ARGS__); \ - static_assert(match_hookable); \ + static_assert(AutoHooks::match_hookable); \ static_assert(std::is_same_v::funcType>, "Hook method signature does not match!"); \ constexpr static const char* name() { return #name_; } \ static const MethodInfo* getInfo() { return ::il2cpp_utils::il2cpp_type_check::MetadataGetter::methodInfo(); } \ @@ -68,7 +66,7 @@ concept match_hookable = has_metadata && Metadata::size >= (0x5 * si #define MAKE_AUTO_HOOK_ORIG_MATCH(name_, mPtr, retval, ...) \ struct Hook_##name_ { \ using funcType = retval (*)(__VA_ARGS__); \ - static_assert(match_hookable); \ + static_assert(AutoHooks::match_hookable); \ static_assert(std::is_same_v::funcType>, "Hook method signature does not match!"); \ constexpr static const char* name() { return #name_; } \ static const MethodInfo* getInfo() { return ::il2cpp_utils::il2cpp_type_check::MetadataGetter::methodInfo(); } \ diff --git a/include/Logger.hpp b/include/Logger.hpp new file mode 100644 index 0000000..b7048d6 --- /dev/null +++ b/include/Logger.hpp @@ -0,0 +1,7 @@ +#pragma once + +#include "beatsaber-hook/shared/utils/logging.hpp" + +/// @brief A logger, useful for printing debug messages +/// @return +inline constexpr auto Logger = Paper::ConstLoggerContext(MOD_ID "_" VERSION); diff --git a/include/main.hpp b/include/main.hpp index e291d6e..22500db 100644 --- a/include/main.hpp +++ b/include/main.hpp @@ -11,10 +11,6 @@ #include "beatsaber-hook/shared/utils/logging.hpp" #include "beatsaber-hook/shared/utils/typedefs.h" -/// @brief A logger, useful for printing debug messages -/// @return -static constexpr auto Logger = Paper::ConstLoggerContext(MOD_ID "_" VERSION); - #define MOD_EXPORT __attribute__((visibility("default"))) #ifdef __cplusplus #define MOD_EXPORT_FUNC extern "C" MOD_EXPORT diff --git a/include/modInfo.hpp b/include/modInfo.hpp new file mode 100644 index 0000000..3f2b4f7 --- /dev/null +++ b/include/modInfo.hpp @@ -0,0 +1,6 @@ +#pragma once + +#include "scotland2/shared/loader.hpp" + +/// @brief Stores the ID and version of our mod, and is sent to the modloader upon startup +inline const modloader::ModInfo modInfo{MOD_ID, VERSION, 0}; diff --git a/src/Hooks/MainViewController.cpp b/src/Hooks/MainViewController.cpp index ad1a4e3..4b609f8 100644 --- a/src/Hooks/MainViewController.cpp +++ b/src/Hooks/MainViewController.cpp @@ -1,5 +1,5 @@ -#include "main.hpp" -#include "autohooks.hpp" +#include "AutoHooks.hpp" +#include "Logger.hpp" // GlobalNamespace #include "GlobalNamespace/MainMenuViewController.hpp" @@ -7,11 +7,14 @@ // UnityEngine #include "UnityEngine/GameObject.hpp" -using namespace GlobalNamespace; +namespace Hooks { + // Usings + using namespace GlobalNamespace; -// Hooks the MainMenuViewController to hide the musicPackPromoBanner object. -MAKE_AUTO_HOOK_MATCH(MainMenuViewController_DidActivate, &MainMenuViewController::DidActivate, void, MainMenuViewController* self, bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling) { - Logger.debug("MainMenuViewController_DidActivate"); - self->____musicPackPromoBanner->get_gameObject()->SetActive(false); - MainMenuViewController_DidActivate(self, firstActivation, addedToHierarchy, screenSystemEnabling); + // Hooks the MainMenuViewController to hide the musicPackPromoBanner object. + MAKE_AUTO_HOOK_MATCH(MainMenuViewController_DidActivate, &MainMenuViewController::DidActivate, void, MainMenuViewController* self, bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling) { + Logger.debug("MainMenuViewController_DidActivate"); + self->____musicPackPromoBanner->get_gameObject()->SetActive(false); + MainMenuViewController_DidActivate(self, firstActivation, addedToHierarchy, screenSystemEnabling); + } } diff --git a/src/main.cpp b/src/main.cpp index b6b171b..8ec3da4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,12 +1,13 @@ #include "main.hpp" -#include "autohooks.hpp" +#include "AutoHooks.hpp" +#include "Logger.hpp" +#include "modInfo.hpp" /// @brief Called at the early stages of game loading /// @param info /// @return MOD_EXPORT_FUNC void setup(CModInfo& info) { - info.id = MOD_ID; - info.version = VERSION; + info = modInfo.to_c(); Logger.info("Completed setup!"); }