Skip to content

Commit

Permalink
Fix FocusLostEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
marioCST committed Nov 17, 2024
1 parent 7e918a3 commit 1f18d0f
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 38 deletions.
2 changes: 0 additions & 2 deletions LatiteRewrite.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,6 @@
<ClInclude Include="src\client\feature\setting\script\JsSetting.h" />
<ClInclude Include="src\client\hook\Hook.h" />
<ClInclude Include="src\client\hook\Hooks.h" />
<ClInclude Include="src\client\hook\impl\AppPlatformHooks.h" />
<ClInclude Include="src\client\hook\impl\DXHooks.h" />
<ClInclude Include="src\client\hook\impl\PlayerHooks.h" />
<ClInclude Include="src\client\hook\impl\GeneralHooks.h" />
Expand Down Expand Up @@ -726,7 +725,6 @@
<ClCompile Include="src\client\feature\module\TextModule.cpp" />
<ClCompile Include="src\client\hook\Hook.cpp" />
<ClCompile Include="src\client\hook\Hooks.cpp" />
<ClCompile Include="src\client\hook\impl\AppPlatformHooks.cpp" />
<ClCompile Include="src\client\hook\impl\DXHooks.cpp" />
<ClCompile Include="src\client\hook\impl\GeneralHooks.cpp" />
<ClCompile Include="src\client\hook\impl\LevelRendererHooks.cpp" />
Expand Down
2 changes: 1 addition & 1 deletion src/client/Latite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
1 change: 0 additions & 1 deletion src/client/hook/Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 0 additions & 2 deletions src/client/hook/Hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -19,7 +18,6 @@ class LatiteHooks final : public StaticManager<HookGroup,
OptionHooks,
DXHooks,
PlayerHooks,
AppPlatformHooks,
MinecraftGameHooks,
RenderControllerHooks,
ScreenViewHooks,
Expand Down
20 changes: 0 additions & 20 deletions src/client/hook/impl/AppPlatformHooks.cpp

This file was deleted.

9 changes: 0 additions & 9 deletions src/client/hook/impl/AppPlatformHooks.h

This file was deleted.

12 changes: 12 additions & 0 deletions src/client/hook/impl/MinecraftGameHooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace {
std::shared_ptr<Hook> onAppSuspendedHook;
std::shared_ptr<Hook> onDeviceLostHook;
std::shared_ptr<Hook> _updateHook;
}

Expand All @@ -22,6 +23,15 @@ void* MinecraftGameHooks::onAppSuspended(SDK::MinecraftGame* game,void*a,void*b,
return onAppSuspendedHook->oFunc<decltype(&onAppSuspended)>()(game,a,b,c);
}

void MinecraftGameHooks::onDeviceLost(SDK::MinecraftGame* game) {
FocusLostEvent ev{};

if (Eventing::get().dispatch(ev))
return;

onDeviceLostHook->oFunc<decltype(&onDeviceLost)>()(game);
}

void __fastcall MinecraftGameHooks::_update(SDK::MinecraftGame* game) {
_updateHook->oFunc<decltype(&_update)>()(game);
UpdateEvent ev{};
Expand All @@ -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");
}
1 change: 1 addition & 0 deletions src/client/hook/impl/MinecraftGameHooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions src/sdk/signature/storage_latest.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 1f18d0f

Please sign in to comment.