From 1f18d0f02fb17f21e73edd066a76f4439c1f713a Mon Sep 17 00:00:00 2001 From: marioCST <68396929+marioCST@users.noreply.github.com> Date: Sun, 17 Nov 2024 16:41:54 +0100 Subject: [PATCH] Fix FocusLostEvent --- LatiteRewrite.vcxproj | 2 -- src/client/Latite.cpp | 2 +- src/client/hook/Hooks.cpp | 1 - src/client/hook/Hooks.h | 2 -- src/client/hook/impl/AppPlatformHooks.cpp | 20 -------------------- src/client/hook/impl/AppPlatformHooks.h | 9 --------- src/client/hook/impl/MinecraftGameHooks.cpp | 12 ++++++++++++ src/client/hook/impl/MinecraftGameHooks.h | 1 + src/sdk/signature/storage_latest.h | 6 +++--- 9 files changed, 17 insertions(+), 38 deletions(-) delete mode 100644 src/client/hook/impl/AppPlatformHooks.cpp delete mode 100644 src/client/hook/impl/AppPlatformHooks.h diff --git a/LatiteRewrite.vcxproj b/LatiteRewrite.vcxproj index 127030ed..7195ae6b 100644 --- a/LatiteRewrite.vcxproj +++ b/LatiteRewrite.vcxproj @@ -468,7 +468,6 @@ - @@ -726,7 +725,6 @@ - diff --git a/src/client/Latite.cpp b/src/client/Latite.cpp index ff9d9579..cf5da2c6 100644 --- a/src/client/Latite.cpp +++ b/src/client/Latite.cpp @@ -197,7 +197,7 @@ DWORD __stdcall startThread(HINSTANCE dll) { MVSIG(ChatScreenController_sendChatMessage), MVSIG(GameRenderer__renderCurrentFrame), MVSIG(onClick), - MVSIG(AppPlatform__fireAppFocusLost), + MVSIG(MinecraftGame_onDeviceLost), MVSIG(MinecraftGame_onAppSuspended), MVSIG(RenderController_getOverlayColor), MVSIG(ScreenView_setupAndRender), diff --git a/src/client/hook/Hooks.cpp b/src/client/hook/Hooks.cpp index 1664d46a..c6123006 100644 --- a/src/client/hook/Hooks.cpp +++ b/src/client/hook/Hooks.cpp @@ -5,7 +5,6 @@ #include "impl/LevelRendererHooks.h" #include "impl/OptionHooks.h" #include "impl/DXHooks.h" -#include "impl/AppPlatformHooks.h" #include "impl/MinecraftGameHooks.h" #include "impl/RenderControllerHooks.h" #include "impl/ScreenViewHooks.h" diff --git a/src/client/hook/Hooks.h b/src/client/hook/Hooks.h index 8b1d2d1f..ff07209e 100644 --- a/src/client/hook/Hooks.h +++ b/src/client/hook/Hooks.h @@ -6,7 +6,6 @@ #include "impl/LevelRendererHooks.h" #include "impl/OptionHooks.h" #include "impl/DXHooks.h" -#include "impl/AppPlatformHooks.h" #include "impl/MinecraftGameHooks.h" #include "impl/RenderControllerHooks.h" #include "impl/ScreenViewHooks.h" @@ -19,7 +18,6 @@ class LatiteHooks final : public StaticManager FocusLostHook; -} - -int AppPlatformHooks::_fireAppFocusLost(SDK::AppPlatform* plat) { - FocusLostEvent ev{}; - if (Eventing::get().dispatch(ev)) return 0; - return FocusLostHook->oFunc()(plat); -} - -AppPlatformHooks::AppPlatformHooks() { - // TODO: FIX ME - //FocusLostHook = addHook(Signatures::AppPlatform__fireAppFocusLost.result, _fireAppFocusLost, "AppPlatform::_fireAppFocusLost"); -} diff --git a/src/client/hook/impl/AppPlatformHooks.h b/src/client/hook/impl/AppPlatformHooks.h deleted file mode 100644 index 473e68f1..00000000 --- a/src/client/hook/impl/AppPlatformHooks.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once -#include "../Hook.h" -#include "sdk/deps/Application/AppPlatform.h" - -class AppPlatformHooks : public HookGroup { - static int __fastcall _fireAppFocusLost(SDK::AppPlatform* plat); -public: - AppPlatformHooks(); -}; \ No newline at end of file diff --git a/src/client/hook/impl/MinecraftGameHooks.cpp b/src/client/hook/impl/MinecraftGameHooks.cpp index 59c886ce..2614ba09 100644 --- a/src/client/hook/impl/MinecraftGameHooks.cpp +++ b/src/client/hook/impl/MinecraftGameHooks.cpp @@ -8,6 +8,7 @@ namespace { std::shared_ptr onAppSuspendedHook; + std::shared_ptr onDeviceLostHook; std::shared_ptr _updateHook; } @@ -22,6 +23,15 @@ void* MinecraftGameHooks::onAppSuspended(SDK::MinecraftGame* game,void*a,void*b, return onAppSuspendedHook->oFunc()(game,a,b,c); } +void MinecraftGameHooks::onDeviceLost(SDK::MinecraftGame* game) { + FocusLostEvent ev{}; + + if (Eventing::get().dispatch(ev)) + return; + + onDeviceLostHook->oFunc()(game); +} + void __fastcall MinecraftGameHooks::_update(SDK::MinecraftGame* game) { _updateHook->oFunc()(game); UpdateEvent ev{}; @@ -37,6 +47,8 @@ void __fastcall MinecraftGameHooks::_update(SDK::MinecraftGame* game) { MinecraftGameHooks::MinecraftGameHooks() { onAppSuspendedHook = addHook(Signatures::MinecraftGame_onAppSuspended.result, onAppSuspended, "MinecraftGame::onAppSuspended"); + onDeviceLostHook = addHook(Signatures::MinecraftGame_onDeviceLost.result, onDeviceLost, + "MinecraftGame::onDeviceLost"); _updateHook = addHook(Signatures::MinecraftGame__update.result, _update, "MinecraftGame::_update"); } diff --git a/src/client/hook/impl/MinecraftGameHooks.h b/src/client/hook/impl/MinecraftGameHooks.h index fcefe2bd..11cc160b 100644 --- a/src/client/hook/impl/MinecraftGameHooks.h +++ b/src/client/hook/impl/MinecraftGameHooks.h @@ -4,6 +4,7 @@ class MinecraftGameHooks : public HookGroup { static void* __fastcall onAppSuspended(SDK::MinecraftGame* game,void*,void*,void*); + static void __fastcall onDeviceLost(SDK::MinecraftGame* game); static void __fastcall _update(SDK::MinecraftGame* game); public: MinecraftGameHooks(); diff --git a/src/sdk/signature/storage_latest.h b/src/sdk/signature/storage_latest.h index d96dac85..a15e3969 100644 --- a/src/sdk/signature/storage_latest.h +++ b/src/sdk/signature/storage_latest.h @@ -139,9 +139,9 @@ class Signatures { "E8 ? ? ? ? 90 EB ? 41 80 BF"_sig, "GameRenderer::_renderCurrentFrame"}; // near "and (displayProperties/realmsPlusEndDate" (below it 1 arg func with 1 arg called src) - inline static SigImpl AppPlatform__fireAppFocusLost{[](memory::signature_store& store, uintptr_t) { return store.deref(1); }, // Call in question is inlined, this is not the correct name anymore - "E8 ? ? ? ? 48 8B 7B ? 0F 1F 80"_sig, - "AppPlatform::_fireAppFocusLost"}; + inline static SigImpl MinecraftGame_onDeviceLost{[](memory::signature_store&, uintptr_t res) { return res; }, + "48 89 5C 24 ? 48 89 74 24 ? 55 57 41 54 41 56 41 57 48 8D 6C 24 ? 48 81 EC ? ? ? ? 4C 8B F9 C7 44 24"_sig, + "MinecraftGame::onDeviceLost"}; inline static SigImpl onClick{[](memory::signature_store&, uintptr_t res) { return res; }, "48 8b c4 48 89 58 ? 48 89 68 ? 48 89 70 ? 57 41 54 41 55 41 56 41 57 48 83 ec ? 44 0f b7 bc 24"_sig,