
27.04.2024, 03:43
|
|
Флудер
Регистрация: 02.02.2019
Сообщений: 5,070
С нами:
3831395
Репутация:
183
|
|
Где ты этот код раздобыл то? Зачем тебе проверка на нажатие в endScene если у тебя уже есть хукнутый wndProc? Ты можешь получать HWND из самой игры, а не через самописные функции ( Просто легче намного ).
Вот код с использованием kthook который нормально работает с endScene:
C++:
Код:
#include
#include
#include
#include
#include "imgui.h"
#include "imgui_impl_dx9.h"
#include "imgui_impl_win32.h"
using
CTimer__UpdateSignature
=
void
(
__cdecl
*
)
(
)
;
using
EndSceneSignature
=
HRESULT
(
__stdcall
*
)
(
IDirect3DDevice9
*
)
;
using
ResetSignature
=
HRESULT
(
__stdcall
*
)
(
IDirect3DDevice9
*
,
D3DPRESENT_PARAMETERS
*
)
;
using
WndProcSignature
=
HRESULT
(
__stdcall
*
)
(
HWND
,
UINT
,
WPARAM
,
LPARAM
)
;
kthook
::
kthook_simple
CTimerHook
{
}
;
kthook
::
kthook_signal
EndSceneHook
{
}
;
kthook
::
kthook_signal
ResetHook
{
}
;
kthook
::
kthook_simple
WndProcHook
{
}
;
extern
IMGUI_IMPL_API LRESULT
ImGui_ImplWin32_WndProcHandler
(
HWND hwnd
,
UINT msg
,
WPARAM wParam
,
LPARAM lParam
)
;
HRESULT
WndProc
(
const
decltype
(
WndProcHook
)
&
hook
,
HWND hwnd
,
UINT uMsg
,
WPARAM wParam
,
LPARAM lParam
)
{
if
(
ImGui_ImplWin32_WndProcHandler
(
hwnd
,
uMsg
,
wParam
,
lParam
)
)
{
return
1
;
}
return
hook
.
get_trampoline
(
)
(
hwnd
,
uMsg
,
wParam
,
lParam
)
;
}
std
::
optional
D3D9EndScene
(
const
decltype
(
EndSceneHook
)
&
hook
,
IDirect3DDevice9
*
pDevice
)
{
static
bool
ImGuiInit
{
}
;
if
(
!
ImGuiInit
)
{
ImGui
::
CreateContext
(
)
;
ImGui_ImplWin32_Init
(
*
*
reinterpret_cast
(
0xC17054
)
)
;
ImGui_ImplDX9_Init
(
pDevice
)
;
ImGui
::
GetIO
(
)
.
IniFilename
=
nullptr
;
#pragma warning(push)
#pragma warning(disable: 4996)
std
::
string font
{
getenv
(
"WINDIR"
)
}
;
font
+=
"\\Fonts\\Arialbd.TTF"
;
#pragma warning(pop)
ImGui
::
GetIO
(
)
.
Fonts
->
AddFontFromFileTTF
(
font
.
c_str
(
)
,
14.0f
,
NULL
,
ImGui
::
GetIO
(
)
.
Fonts
->
GetGlyphRangesCyrillic
(
)
)
;
auto
latest_wndproc_ptr
=
GetWindowLongPtrW
(
*
*
reinterpret_cast
(
0xC17054
)
,
GWLP_WNDPROC
)
;
WndProcHook
.
set_dest
(
latest_wndproc_ptr
)
;
WndProcHook
.
set_cb
(
&
WndProc
)
;
WndProcHook
.
install
(
)
;
ImGuiInit
=
{
true
}
;
}
ImGui_ImplDX9_NewFrame
(
)
;
ImGui_ImplWin32_NewFrame
(
)
;
ImGui
::
NewFrame
(
)
;
auto
dl
=
ImGui
::
GetBackgroundDrawList
(
)
;
dl
->
AddText
(
ImVec2
(
200.f
,
200.f
)
,
-
1
,
"WORK"
)
;
ImGui
::
EndFrame
(
)
;
ImGui
::
Render
(
)
;
ImGui_ImplDX9_RenderDrawData
(
ImGui
::
GetDrawData
(
)
)
;
return
std
::
nullopt
;
}
std
::
optional
D3D9Lost
(
const
decltype
(
ResetHook
)
&
hook
,
LPDIRECT3DDEVICE9 pDevice
,
D3DPRESENT_PARAMETERS
*
pPresentParams
)
{
ImGui_ImplDX9_InvalidateDeviceObjects
(
)
;
return
std
::
nullopt
;
}
void
D3D9Reset
(
const
decltype
(
ResetHook
)
&
hook
,
HRESULT
&
return_value
,
IDirect3DDevice9
*
device_ptr
,
D3DPRESENT_PARAMETERS
*
parameters
)
{
ImGui_ImplDX9_InvalidateDeviceObjects
(
)
;
}
void
setD3D9Hooks
(
)
{
DWORD pDevice
=
*
reinterpret_cast
(
0xC97C28
)
;
void
*
*
vTable
=
*
reinterpret_cast
(
pDevice
)
;
EndSceneHook
.
set_dest
(
vTable
[
42
]
)
;
EndSceneHook
.
before
.
connect
(
&
D3D9EndScene
)
;
EndSceneHook
.
install
(
)
;
ResetHook
.
set_dest
(
vTable
[
16
]
)
;
ResetHook
.
before
.
connect
(
&
D3D9Lost
)
;
ResetHook
.
after
.
connect
(
&
D3D9Reset
)
;
ResetHook
.
install
(
)
;
}
void
CTimer__Update
(
const
decltype
(
CTimerHook
)
&
hook
)
{
static
bool
init
{
}
;
if
(
!
init
)
{
setD3D9Hooks
(
)
;
init
=
{
true
}
;
}
hook
.
get_trampoline
(
)
(
)
;
}
BOOL APIENTRY
DllMain
(
HMODULE hModule
,
DWORD ul_reason_for_call
,
LPVOID lpReserved
)
{
switch
(
ul_reason_for_call
)
{
case
DLL_PROCESS_ATTACH
:
CTimerHook
.
set_dest
(
0x561B10
)
;
CTimerHook
.
set_cb
(
&
CTimer__Update
)
;
CTimerHook
.
install
(
)
;
break
;
case
DLL_PROCESS_DETACH
:
WndProcHook
.
remove
(
)
;
ResetHook
.
remove
(
)
;
EndSceneHook
.
remove
(
)
;
CTimerHook
.
remove
(
)
;
break
;
}
return
TRUE
;
}
|
|
|