From 41aef57758d7b858d5fa7cb22ab1ffe603ff365f Mon Sep 17 00:00:00 2001 From: camila314 <47485054+camila314@users.noreply.github.com> Date: Thu, 9 Feb 2023 09:45:06 -0600 Subject: [PATCH 1/3] make >= default prevent issues --- loader/include/Geode/utils/VersionInfo.hpp | 11 +++++++---- loader/src/utils/VersionInfo.cpp | 9 +++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/loader/include/Geode/utils/VersionInfo.hpp b/loader/include/Geode/utils/VersionInfo.hpp index 2744300b..f94472ca 100644 --- a/loader/include/Geode/utils/VersionInfo.hpp +++ b/loader/include/Geode/utils/VersionInfo.hpp @@ -121,12 +121,15 @@ namespace geode { if (m_version.getMajor() != version.getMajor()) { return false; } + switch (m_compare) { - case VersionCompare::Exact: return m_version == version; break; - case VersionCompare::LessEq: return m_version <= version; break; - case VersionCompare::MoreEq: return m_version >= version; break; + case VersionCompare::LessEq: + return m_version <= version; + case VersionCompare::MoreEq: + return m_version >= version; + default: + return m_version == version; } - return false; } std::string toString() const; diff --git a/loader/src/utils/VersionInfo.cpp b/loader/src/utils/VersionInfo.cpp index f0abafc3..13f8aad7 100644 --- a/loader/src/utils/VersionInfo.cpp +++ b/loader/src/utils/VersionInfo.cpp @@ -115,15 +115,16 @@ Result ComparableVersionInfo::parse(std::string const& ra if (string.starts_with("<=")) { compare = VersionCompare::LessEq; string.erase(0, 2); - } - else if (string.starts_with(">=")) { + } else if (string.starts_with(">=")) { compare = VersionCompare::MoreEq; string.erase(0, 2); - } - else if (string.starts_with("=")) { + } else if (string.starts_with("=")) { compare = VersionCompare::Exact; string.erase(0, 1); + } else { + compare = VersionCompare::MoreEq; } + GEODE_UNWRAP_INTO(auto version, VersionInfo::parse(string)); return Ok(ComparableVersionInfo(version, compare)); } From 65f2cbb286cc1e5af57e43451862a2233d66453e Mon Sep 17 00:00:00 2001 From: matcool <26722564+matcool@users.noreply.github.com> Date: Thu, 9 Feb 2023 13:54:30 -0300 Subject: [PATCH 2/3] follow thunk functions for non virtuals --- loader/include/Geode/utils/addresser.hpp | 27 ++++++++++++++---------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/loader/include/Geode/utils/addresser.hpp b/loader/include/Geode/utils/addresser.hpp index d37e65a6..eb458ffa 100644 --- a/loader/include/Geode/utils/addresser.hpp +++ b/loader/include/Geode/utils/addresser.hpp @@ -131,15 +131,7 @@ namespace geode::addresser { // [[this + thunk] + offset] is the f we want auto address = *(intptr_t*)(*(intptr_t*)(reference_cast(ins) + thunk) + index); -#ifdef GEODE_IS_WINDOWS - // check if first instruction is a jmp, i.e. if the func is a thunk - if (*reinterpret_cast(address) == 0x25ff) { - // read where the jmp points to and jump there - address = *reinterpret_cast(address + 2); - // that then contains the actual address of the func - address = *reinterpret_cast(address); - } -#endif + address = followThunkFunction(address); return address; } @@ -171,14 +163,27 @@ namespace geode::addresser { return addressOfNonVirtual(reinterpret_cast(func)); } + static inline intptr_t followThunkFunction(intptr_t address) { +#ifdef GEODE_IS_WINDOWS + // check if first instruction is a jmp dword ptr [....], i.e. if the func is a thunk + if (*reinterpret_cast(address) == 0xFF && *reinterpret_cast(address + 1) == 0x25) { + // read where the jmp reads from + address = *reinterpret_cast(address + 2); + // that then contains the actual address of the func + address = *reinterpret_cast(address); + } +#endif + return address; + } + template static intptr_t addressOfNonVirtual(R (T::*func)(Ps...)) { - return geode::cast::reference_cast(func); + return followThunkFunction(geode::cast::reference_cast(func)); } template static intptr_t addressOfNonVirtual(R (*func)(Ps...)) { - return geode::cast::reference_cast(func); + return followThunkFunction(geode::cast::reference_cast(func)); } template From ee73b25247ea6cd4004376a92bf76dc77ab35650 Mon Sep 17 00:00:00 2001 From: matcool <26722564+matcool@users.noreply.github.com> Date: Thu, 9 Feb 2023 14:01:52 -0300 Subject: [PATCH 3/3] potentially fix codegen cache mismatch --- CMakeLists.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 92540ae4..133fa304 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -77,8 +77,10 @@ set(GEODE_CODEGEN_BINARY_OUT ${CMAKE_CURRENT_BINARY_DIR}/codegen) ExternalProject_Add(CodegenProject BUILD_ALWAYS ON SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/codegen - CMAKE_CACHE_ARGS "-DCMAKE_INSTALL_PREFIX:STRING=${GEODE_CODEGEN_BINARY_OUT}" - CMAKE_ARGS ${GEODE_CODEGEN_CMAKE_ARGS} + # manually set configure command as to not inherit generator used by geode, + # this should hopefully fix generator cache mismatch between different projects, however + # it causes a warning to be shown every time. if you know a better solution please tell us ok thx + CONFIGURE_COMMAND ${CMAKE_COMMAND} ${GEODE_CODEGEN_CMAKE_ARGS} -DCMAKE_INSTALL_PREFIX:STRING=${GEODE_CODEGEN_BINARY_OUT} -S -B )