Fix nullptr problems (#878)

This commit is contained in:
kizer 2022-06-04 20:45:22 +09:00 committed by GitHub
parent 74966fc4ef
commit 71f3680388
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 161 additions and 84 deletions

View file

@ -137,12 +137,14 @@ namespace utils {
static constexpr uint64_t Placeholder = 0xCC90CC90CC90CC90ULL;
const std::shared_ptr<void> m_pThunk;
std::string m_name;
std::function<TFn> m_fnTarget;
public:
thunk(std::function<TFn> target)
thunk(std::string name, std::function<TFn> target)
: m_pThunk(utils::create_thunk(&detour_static, this, Placeholder))
, m_fnTarget(std::move(target)) {
, m_fnTarget(std::move(target))
, m_name(name) {
}
void set_target(std::function<TFn> detour) {
@ -153,6 +155,10 @@ namespace utils {
return reinterpret_cast<TFn*>(m_pThunk.get());
}
const std::string& name() const {
return m_name;
}
private:
// mark it as virtual to prevent compiler from inlining
virtual TReturn detour(TArgs... args) {
@ -249,4 +255,10 @@ namespace utils {
bool is_running_on_linux();
std::filesystem::path get_module_path(HMODULE hModule);
/// @brief Find the game main window.
/// @return Handle to the game main window, or nullptr if it doesn't exist (yet).
HWND try_find_game_window();
void wait_for_game_window();
}