Показать сообщение отдельно

  #3  
Старый 08.04.2019, 06:46
deropleat
Участник форума
Регистрация: 16.03.2017
Сообщений: 105
С нами: 4821087

Репутация: 133
По умолчанию

Немного другой хук, который не требует очистки девайса под итог.

VMTHook.h

C++:





Код:
#pragma once
#include 
#include 
#include 
#include 
class
VMTHook
{
private
:
std
::
uintptr_t
*
*
BaseClass
=
nullptr
;
std
::
unique_ptr

CurrentVTF
=
nullptr
;
std
::
uintptr_t
*
OriginalVTF
=
nullptr
;
std
::
size_t TotalFuncs
=
0
;
public
:
VMTHook
(
void
)
=
default
;
VMTHook
(
void
*
BaseClass
)
{
this
->
BaseClass
=
static_cast

(
BaseClass
)
;
while
(
static_cast

(
*
this
->
BaseClass
)
[
this
->
TotalFuncs
]
)
++
this
->
TotalFuncs
;
const
std
::
size_t TableSize
=
this
->
TotalFuncs
*
sizeof
(
std
::
uintptr_t
)
;
this
->
OriginalVTF
=
*
this
->
BaseClass
;
this
->
CurrentVTF
=
std
::
make_unique

(
this
->
TotalFuncs
)
;
std
::
memcpy
(
this
->
CurrentVTF
.
get
(
)
,
this
->
OriginalVTF
,
TableSize
)
;
*
this
->
BaseClass
=
this
->
CurrentVTF
.
get
(
)
;
}
;
~
VMTHook
(
)
{
*
this
->
BaseClass
=
this
->
OriginalVTF
;
}
;
template

inline
const
Fn
GetOrigIndex
(
std
::
size_t FunctionIndex
)
{
return
reinterpret_cast

(
this
->
OriginalVTF
[
FunctionIndex
]
)
;
}
inline
bool
TableIndexHook
(
void
*
new_function
,
const
std
::
size_t FunctionIndex
)
{
if
(
FunctionIndex
>
this
->
TotalFuncs
)
return
false
;
this
->
CurrentVTF
[
FunctionIndex
]
=
reinterpret_cast

(
new_function
)
;
return
true
;
}
inline
bool
TableIndexUnHook
(
const
std
::
size_t FunctionIndex
)
{
if
(
FunctionIndex
>
this
->
TotalFuncs
)
return
false
;
this
->
CurrentVTF
[
FunctionIndex
]
=
this
->
OriginalVTF
[
FunctionIndex
]
;
return
true
;
}
inline
std
::
size_t
GetMaxIndex
(
)
{
return
this
->
TotalFuncs
;
}
}
;


Hooks.cpp

C++:





Код:
using
PresentFn
=
long
(
__stdcall
*
)
(
IDirect3DDevice9
*
,
const
RECT
*
,
const
RECT
*
,
HWND
,
const
RGNDATA
*
)
;
long
__stdcall g_pHooks
::
Present
(
IDirect3DDevice9
*
pDevice
,
const
RECT
*
pSourceRect
,
const
RECT
*
pDestRect
,
HWND hDestWindowOverride
,
const
RGNDATA
*
pDirtyRegion
)
{
static
auto
OriginalFunc
=
MyDevice
->
GetOrigIndex

(
17
)
;
if
(
!
init
)
g_pRender
->
Init
(
pDevice
,
init
)
;
g_pRender
->
PaintBegin
(
)
;
g_pRender
->
SizeReset
(
)
;
pDevice
->
SetRenderState
(
D3DRS_SRGBWRITEENABLE
,
false
)
;
g_pMenu
->
MyDevice
=
pDevice
;
g_pMenu
->
Update
(
)
;
return
OriginalFunc
(
pDevice
,
pSourceRect
,
pDestRect
,
hDestWindowOverride
,
pDirtyRegion
)
;
}


Render.cpp

C++:





Код:
void
CRender
::
Line
(
int
sX
,
int
sY
,
int
eX
,
int
eY
,
D3DCOLOR D3DCOLOR
)
{
vertex pVertex
[
2
]
=
{
{
sX
,
sY
,
0.0f
,
1.0f
,
D3DCOLOR
}
,
{
eX
,
eY
,
0.0f
,
1.0f
,
D3DCOLOR
}
}
;
MyDevice
->
SetRenderState
(
D3DRS_LIGHTING
,
FALSE
)
;
MyDevice
->
SetRenderState
(
D3DRS_ZENABLE
,
D3DZB_FALSE
)
;
MyDevice
->
SetRenderState
(
D3DRS_FOGENABLE
,
FALSE
)
;
MyDevice
->
SetRenderState
(
D3DRS_CULLMODE
,
D3DCULL_NONE
)
;
MyDevice
->
SetRenderState
(
D3DRS_ALPHABLENDENABLE
,
TRUE
)
;
MyDevice
->
SetRenderState
(
D3DRS_SRCBLEND
,
D3DBLEND_SRCALPHA
)
;
MyDevice
->
SetRenderState
(
D3DRS_DESTBLEND
,
D3DBLEND_INVSRCALPHA
)
;
MyDevice
->
SetRenderState
(
D3DRS_LIGHTING
,
FALSE
)
;
MyDevice
->
SetRenderState
(
D3DRS_STENCILENABLE
,
FALSE
)
;
MyDevice
->
SetTexture
(
0
,
NULL
)
;
MyDevice
->
SetPixelShader
(
NULL
)
;
MyDevice
->
SetFVF
(
D3DFVF_XYZRHW
|
D3DFVF_DIFFUSE
|
D3DFVF_TEX1
)
;
MyDevice
->
DrawPrimitiveUP
(
D3DPT_LINELIST
,
1
,
&
pVertex
,
sizeof
(
vertex
)
)
;
}


48BRHEEGO_4.jpgderopleat · 8 Апр 2019 в 05:46' data-fancybox="lb-post-323608" data-lb-caption-extra-html="" data-lb-sidebar-href="" data-single-image="1" data-src="/proxy.php?image=https%3A%2F%2Fpp.userapi.com%2Fc85 0524%2Fv850524518%2Ff4913%2F48BRHEEGO_4.jpg&hash=8 7c49eff87663a7fd396f76b793a072a" style="cursor: pointer;" title="48BRHEEGO_4.jpg">
 
Ответить с цитированием