| nonelike |
07.06.2025 19:33 |
Цитата:
Сообщение от dmitry.karle
overlay.hpp:
Код:
#ifndef OVERLAY_HPP
#define OVERLAY_HPP
#include
#include
#include "render.hpp"
class c_overlay : public CefClient, public CefRenderHandler, public CefLifeSpanHandler {
public:
c_overlay() = default;
~c_overlay() = default;
virtual CefRefPtr GetRenderHandler() override { return this; };
virtual CefRefPtr GetLifeSpanHandler() override { return this; }
virtual void OnAfterCreated(CefRefPtr browser) override {
this->browser = browser;
browser->GetHost()->SetWindowlessFrameRate(60); --для фпса
}
void OnPaint(CefRefPtr browser, PaintElementType type, const RectList& dirty_rects, const void* buffer, int width, int height) override;
void GetViewRect(CefRefPtr browser, CefRect& rect) override { rect = CefRect(0, 0, 840, 660); };
CefRefPtr GetBrowser() { return this->browser; };
private:
CefRefPtr browser;
IMPLEMENT_REFCOUNTING(c_overlay);
DISALLOW_COPY_AND_ASSIGN(c_overlay);
};
namespace overlay {
inline static c_overlay* cef;
inline LPDIRECT3DTEXTURE9 texture = nullptr;
inline int texture_width = 0;
inline int texture_height = 0;
inline bool needs_update = false;
void initialize();
void create_browser(std::string url = "https://url.com");
bool wnd_proc(HWND hwnd, UINT umsg, WPARAM wp, LPARAM lp);
void destroy();
}
#endif // !OVERLAY_HPP
plugin.cpp:
Код:
void c_plugin::update_hooked(const decltype(update_hook)& hook) {
static bool inited = false;
if (!inited && c_chat().reference() && rakhook::initialize()) {
inited = true;
overlay::initialize();
render::initialize();
render::on_present += []() {
if (!overlay::texture || !render::device || !overlay::needs_update)
return;
// сохранения состояния
D3DVIEWPORT9 old_viewport;
IDirect3DStateBlock9* state_block = nullptr;
render::device->CreateStateBlock(D3DSBT_ALL, &state_block);
render::device->GetViewport(&old_viewport);
// параметры для рендера
D3DVIEWPORT9 viewport = {0, 0, 840, 660, 0.0f, 1.0f};
render::device->SetViewport(&viewport);
render::device->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
render::device->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
render::device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
render::device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
render::device->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE);
render::device->SetRenderState(D3DRS_ALPHAREF, 0x08);
render::device->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL);
render::device->SetRenderState(D3DRS_LIGHTING, FALSE);
render::device->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
render::device->SetRenderState(D3DRS_SCISSORTESTENABLE, FALSE);
render::device->SetTexture(0, overlay::texture);
render::device->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
render::device->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
render::device->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
render::device->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
render::device->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
render::device->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
render::device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
render::device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
struct CUSTOMVERTEX {
FLOAT x, y, z, rhw;
DWORD color;
FLOAT tu, tv;
};
CUSTOMVERTEX vertices[] = {
{ 0.0f, 0.0f, 0.0f, 1.0f, 0xFFFFFFFF, 0.0f, 0.0f },
{ 840.0f, 0.0f, 0.0f, 1.0f, 0xFFFFFFFF, 1.0f, 0.0f },
{ 0.0f, 660.0f, 0.0f, 1.0f, 0xFFFFFFFF, 0.0f, 1.0f },
{ 840.0f, 660.0f, 0.0f, 1.0f, 0xFFFFFFFF, 1.0f, 1.0f }
};
render::device->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1);
render::device->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, vertices, sizeof(CUSTOMVERTEX));
if (state_block) {
state_block->Apply();
state_block->Release();
}
render::device->SetViewport(&old_viewport);
overlay::needs_update = false;
};
}
return hook.call_trampoline();
}
cpp:
Код:
#include "overlay.hpp"
#include
namespace overlay {
inline static c_overlay* cef = nullptr;
inline LPDIRECT3DTEXTURE9 texture = nullptr;
inline int texture_width = 0;
inline int texture_height = 0;
inline bool needs_update = false;
inline bool browser_created = false;
}
void c_overlay::OnPaint(CefRefPtr browser, PaintElementType type, const RectList& dirty_rects, const void* buffer, int width, int height) {
// two check and buffer
if (width Release();
overlay::texture = nullptr;
}
HRESULT hr = D3DXCreateTexture(
render::device,
width,
height,
1,
D3DUSAGE_DYNAMIC,
D3DFMT_A8R8G8B8,
D3DPOOL_DEFAULT,
&overlay::texture
);
if (FAILED(hr) {
return;
}
overlay::texture_width = width;
overlay::texture_height = height;
texture_needs_update = true;
}
// update texture
D3DLOCKED_RECT locked_rect;
if (overlay::texture->LockRect(0, &locked_rect, nullptr, D3DLOCK_DISCARD) == D3D_OK) {
const uint8_t* src = static_cast(buffer);
uint8_t* dst = static_cast(locked_rect.pBits);
if (locked_rect.Pitch == width * 4) {
memcpy(dst, src, width * height * 4);
} else {
for (int y = 0; y UnlockRect(0);
overlay::needs_update = true;
}
}
void overlay::create_browser(std::string url) {
if (browser_created) return;
CefWindowInfo window_info;
CefBrowserSettings browser_settings;
browser_settings.windowless_frame_rate = 60;
browser_settings.background_color = 0x00000000;
browser_settings.webgl = STATE_DISABLED;
browser_settings.plugins = STATE_DISABLED;
window_info.SetAsWindowless(nullptr);
window_info.shared_texture_enabled = false;
window_info.external_begin_frame_enabled = false;
CefBrowserHost::CreateBrowser(
window_info,
cef,
url,
browser_settings,
nullptr,
nullptr
);
browser_created = true;
}
void overlay::initialize() {
if (cef) return;
CefMainArgs main_args(GetModuleHandle(nullptr));
CefSettings settings;
std::string work_path = std::filesystem::current_path().string();
std::filesystem::create_directories(work_path + "\\cef_cache");
CefString(&settings.browser_subprocess_path).FromString(work_path + "\\cef_subprocess.exe");
CefString(&settings.cache_path).FromString(work_path + "\\cef_cache");
CefString(&settings.locales_dir_path).FromString(work_path + "\\locales");
CefString(&settings.resources_dir_path).FromString(work_path);
CefString(&settings.locale).FromString("ru");
CefString(&settings.accept_language_list).FromString("ru-RU,ru,en-US,en");
settings.windowless_rendering_enabled = true;
settings.no_sandbox = true;
settings.multi_threaded_message_loop = true;
settings.background_color = 0x00000000;
settings.log_severity = LOGSEVERITY_DISABLE;
settings.command_line_args_disabled = true;
settings.pack_loading_disabled = false;
if (!CefInitialize(main_args, settings, nullptr, nullptr)) {
return;
}
cef = new c_overlay();
create_browser();
}
bool overlay::wnd_proc(HWND hwnd, UINT umsg, WPARAM wp, LPARAM lp) {
if (!cef || !cef->GetBrowser()) {
return false;
}
CefRefPtr host = cef->GetBrowser()->GetHost();
// обработка мыши
if (umsg >= WM_MOUSEFIRST && umsg SendMouseMoveEvent(mouse_event, false);
return true;
case WM_LBUTTONDOWN:
host->SendMouseClickEvent(mouse_event, MBT_LEFT, false, 1);
return true;
case WM_LBUTTONUP:
host->SendMouseClickEvent(mouse_event, MBT_LEFT, true, 1);
return true;
case WM_RBUTTONDOWN:
host->SendMouseClickEvent(mouse_event, MBT_RIGHT, false, 1);
return true;
case WM_RBUTTONUP:
host->SendMouseClickEvent(mouse_event, MBT_RIGHT, true, 1);
return true;
case WM_MOUSEWHEEL:
host->SendMouseWheelEvent(mouse_event, 0, GET_WHEEL_DELTA_WPARAM(wp));
return true;
}
}
// обработка клавы
if (umsg >= WM_KEYFIRST && umsg (wp);
event.native_key_code = static_cast(lp);
event.modifiers = GetCefModifiers();
if (umsg == WM_KEYDOWN || umsg == WM_SYSKEYDOWN) {
event.type = KEYEVENT_RAWKEYDOWN;
} else if (umsg == WM_KEYUP || umsg == WM_SYSKEYUP) {
event.type = KEYEVENT_KEYUP;
} else if (umsg == WM_CHAR) {
event.type = KEYEVENT_CHAR;
}
// esc
if (event.windows_key_code == VK_ESCAPE && event.type == KEYEVENT_RAWKEYDOWN) {
return false;
}
host->SendKeyEvent(event);
return true;
}
return false;
}
void overlay::destroy() {
if (texture) {
texture->Release();
texture = nullptr;
}
if (cef) {
if (cef->GetBrowser()) {
cef->GetBrowser()->GetHost()->CloseBrowser(true);
}
delete cef;
cef = nullptr;
}
CefShutdown();
}
// help func or modification
int GetCefModifiers() {
int modifiers = 0;
if (GetKeyState(VK_SHIFT) & 0x8000) modifiers |= EVENTFLAG_SHIFT_DOWN;
if (GetKeyState(VK_CONTROL) & 0x8000) modifiers |= EVENTFLAG_CONTROL_DOWN;
if (GetKeyState(VK_MENU) & 0x8000) modifiers |= EVENTFLAG_ALT_DOWN;
if (GetKeyState(VK_CAPITAL) & 0x0001) modifiers |= EVENTFLAG_CAPS_LOCK_ON;
return modifiers;
}
хз, проверь это, 3 cpp полностью переписан и должен быть улучшенный рендер
|
теперь крашится игра, вижу на секунду что текстурка начинает рисоваться белая, а после игра крашится, на всякий случай приложу код, мб чето не так копипастнул
render.hpp:
Код:
#ifndef RENDER_HPP
#define RENDER_HPP
#include
#include
#include
#include
#include
#pragma comment (lib, "d3d9.lib")
#pragma comment (lib, "d3dx9.lib")
#include "kthook/kthook.hpp"
#include "samp.hpp"
namespace
render
{
template
struct
on_event
:
public
std
::
vector
>
{
on_event
&
operator
+=
(
std
::
function
func
)
{
this
->
push_back
(
func
)
;
return
*
this
;
}
}
;
inline
on_event
on_present
;
inline
bool
initialized
=
false
;
inline
IDirect3DDevice9
*
device
;
void
initialize
(
)
;
void
destroy
(
)
;
}
#endif
// !RENDER_HPP
plugin.hpp:
Код:
#ifndef PLUGIN_HPP
#define PLUGIN_HPP
#include
#include
#include
#include "overlay.hpp"
using
namespace
std
::
placeholders
;
class
c_plugin
{
public
:
c_plugin
(
)
=
default
;
~
c_plugin
(
)
{
rakhook
::
destroy
(
)
;
render
::
destroy
(
)
;
overlay
::
destroy
(
)
;
}
;
kthook
::
kthook_simple
update_hook
{
reinterpret_cast
(
0x561B10
)
,
std
::
bind
(
&
c_plugin
::
update_hooked
,
this
,
_1
)
}
;
void
update_hooked
(
const
decltype
(
update_hook
)
&
hook
)
;
kthook
::
kthook_simple
wnd_proc_hook
{
reinterpret_cast
(
0x747EB0
)
,
std
::
bind
(
&
c_plugin
::
wnd_proc_hooked
,
this
,
_1
,
_2
,
_3
,
_4
,
_5
)
}
;
HRESULT
wnd_proc_hooked
(
const
decltype
(
wnd_proc_hook
)
&
hook
,
HWND hwnd
,
UINT umsg
,
WPARAM wp
,
LPARAM lp
)
;
}
;
#endif
// PLUGIN_HPP
overlay.hpp:
Код:
#ifndef OVERLAY_HPP
#define OVERLAY_HPP
#include
#include
#include "render.hpp"
#include
class
c_overlay
:
public
CefClient
,
public
CefRenderHandler
,
public
CefLifeSpanHandler
{
public
:
c_overlay
(
)
=
default
;
~
c_overlay
(
)
=
default
;
virtual
CefRefPtr
GetRenderHandler
(
)
override
{
return
this
;
}
;
virtual
CefRefPtr
GetLifeSpanHandler
(
)
override
{
return
this
;
}
virtual
void
OnAfterCreated
(
CefRefPtr
browser
)
override
{
this
->
browser
=
browser
;
browser
->
GetHost
(
)
->
SetWindowlessFrameRate
(
60
)
;
}
void
OnPaint
(
CefRefPtr
browser
,
PaintElementType type
,
const
RectList
&
dirty_rects
,
const
void
*
buffer
,
int
width
,
int
height
)
override
;
void
GetViewRect
(
CefRefPtr
browser
,
CefRect
&
rect
)
override
{
rect
=
CefRect
(
0
,
0
,
840
,
660
)
;
}
;
CefRefPtr
GetBrowser
(
)
{
return
this
->
browser
;
}
;
private
:
CefRefPtr
browser
;
IMPLEMENT_REFCOUNTING
(
c_overlay
)
;
DISALLOW_COPY_AND_ASSIGN
(
c_overlay
)
;
}
;
namespace
overlay
{
inline
static
c_overlay
*
cef
;
inline
LPDIRECT3DTEXTURE9 texture
=
nullptr
;
inline
int
texture_width
=
0
;
inline
int
texture_height
=
0
;
inline
bool
needs_update
=
false
;
inline
bool
browser_created
=
false
;
void
initialize
(
)
;
void
create_browser
(
std
::
string url
=
"file:///C:/Bounce.html"
)
;
bool
wnd_proc
(
HWND hwnd
,
UINT umsg
,
WPARAM wp
,
LPARAM lp
)
;
void
destroy
(
)
;
}
#endif
// !OVERLAY_HPP
plugin.cpp:
Код:
#include "plugin.hpp"
void
c_plugin
::
update_hooked
(
const
decltype
(
update_hook
)
&
hook
)
{
static
bool
inited
=
false
;
if
(
!
inited
&&
c_chat
(
)
.
reference
(
)
&&
rakhook
::
initialize
(
)
)
{
inited
=
true
;
overlay
::
initialize
(
)
;
render
::
initialize
(
)
;
render
::
on_present
+=
[
]
(
)
{
if
(
!
overlay
::
texture
||
!
render
::
device
||
!
overlay
::
needs_update
)
{
OutputDebugString
(
"!overlay"
)
;
}
// сохранения состояния
D3DVIEWPORT9 old_viewport
;
IDirect3DStateBlock9
*
state_block
=
nullptr
;
render
::
device
->
CreateStateBlock
(
D3DSBT_ALL
,
&
state_block
)
;
render
::
device
->
GetViewport
(
&
old_viewport
)
;
// параметры для рендера
D3DVIEWPORT9 viewport
=
{
0
,
0
,
840
,
660
,
0.0f
,
1.0f
}
;
render
::
device
->
SetViewport
(
&
viewport
)
;
render
::
device
->
SetRenderState
(
D3DRS_ZENABLE
,
D3DZB_FALSE
)
;
render
::
device
->
SetRenderState
(
D3DRS_ALPHABLENDENABLE
,
TRUE
)
;
render
::
device
->
SetRenderState
(
D3DRS_SRCBLEND
,
D3DBLEND_SRCALPHA
)
;
render
::
device
->
SetRenderState
(
D3DRS_DESTBLEND
,
D3DBLEND_INVSRCALPHA
)
;
render
::
device
->
SetRenderState
(
D3DRS_ALPHATESTENABLE
,
TRUE
)
;
render
::
device
->
SetRenderState
(
D3DRS_ALPHAREF
,
0x08
)
;
render
::
device
->
SetRenderState
(
D3DRS_ALPHAFUNC
,
D3DCMP_GREATEREQUAL
)
;
render
::
device
->
SetRenderState
(
D3DRS_LIGHTING
,
FALSE
)
;
render
::
device
->
SetRenderState
(
D3DRS_CULLMODE
,
D3DCULL_NONE
)
;
render
::
device
->
SetRenderState
(
D3DRS_SCISSORTESTENABLE
,
FALSE
)
;
render
::
device
->
SetTexture
(
0
,
overlay
::
texture
)
;
render
::
device
->
SetTextureStageState
(
0
,
D3DTSS_COLOROP
,
D3DTOP_MODULATE
)
;
render
::
device
->
SetTextureStageState
(
0
,
D3DTSS_COLORARG1
,
D3DTA_TEXTURE
)
;
render
::
device
->
SetTextureStageState
(
0
,
D3DTSS_COLORARG2
,
D3DTA_DIFFUSE
)
;
render
::
device
->
SetTextureStageState
(
0
,
D3DTSS_ALPHAOP
,
D3DTOP_MODULATE
)
;
render
::
device
->
SetTextureStageState
(
0
,
D3DTSS_ALPHAARG1
,
D3DTA_TEXTURE
)
;
render
::
device
->
SetTextureStageState
(
0
,
D3DTSS_ALPHAARG2
,
D3DTA_DIFFUSE
)
;
render
::
device
->
SetSamplerState
(
0
,
D3DSAMP_MINFILTER
,
D3DTEXF_LINEAR
)
;
render
::
device
->
SetSamplerState
(
0
,
D3DSAMP_MAGFILTER
,
D3DTEXF_LINEAR
)
;
struct
CUSTOMVERTEX
{
FLOAT x
,
y
,
z
,
rhw
;
DWORD color
;
FLOAT tu
,
tv
;
}
;
CUSTOMVERTEX vertices
[
]
=
{
{
0.0f
,
0.0f
,
0.0f
,
1.0f
,
0xFFFFFFFF
,
0.0f
,
0.0f
}
,
{
840.0f
,
0.0f
,
0.0f
,
1.0f
,
0xFFFFFFFF
,
1.0f
,
0.0f
}
,
{
0.0f
,
660.0f
,
0.0f
,
1.0f
,
0xFFFFFFFF
,
0.0f
,
1.0f
}
,
{
840.0f
,
660.0f
,
0.0f
,
1.0f
,
0xFFFFFFFF
,
1.0f
,
1.0f
}
}
;
render
::
device
->
SetFVF
(
D3DFVF_XYZRHW
|
D3DFVF_DIFFUSE
|
D3DFVF_TEX1
)
;
render
::
device
->
DrawPrimitiveUP
(
D3DPT_TRIANGLESTRIP
,
2
,
vertices
,
sizeof
(
CUSTOMVERTEX
)
)
;
if
(
state_block
)
{
state_block
->
Apply
(
)
;
state_block
->
Release
(
)
;
}
render
::
device
->
SetViewport
(
&
old_viewport
)
;
overlay
::
needs_update
=
false
;
}
;
}
return
hook
.
call_trampoline
(
)
;
}
HRESULT c_plugin
::
wnd_proc_hooked
(
const
decltype
(
wnd_proc_hook
)
&
hook
,
HWND hwnd
,
UINT umsg
,
WPARAM wp
,
LPARAM lp
)
{
overlay
::
wnd_proc
(
hwnd
,
umsg
,
wp
,
lp
)
;
return
hook
.
call_trampoline
(
hwnd
,
umsg
,
wp
,
lp
)
;
}
overlay.cpp:
Код:
#include "overlay.hpp"
#include
void
c_overlay
::
OnPaint
(
CefRefPtr
browser
,
PaintElementType type
,
const
RectList
&
dirty_rects
,
const
void
*
buffer
,
int
width
,
int
height
)
{
// two check and buffer
if
(
width
Release
(
)
;
overlay
::
texture
=
nullptr
;
}
HRESULT hr
=
D3DXCreateTexture
(
render
::
device
,
width
,
height
,
1
,
D3DUSAGE_DYNAMIC
,
D3DFMT_A8R8G8B8
,
D3DPOOL_DEFAULT
,
&
overlay
::
texture
)
;
if
(
FAILED
(
hr
)
)
{
OutputDebugString
(
"failed hr"
)
;
}
overlay
::
texture_width
=
width
;
overlay
::
texture_height
=
height
;
texture_needs_update
=
true
;
}
// update texture
D3DLOCKED_RECT locked_rect
;
if
(
overlay
::
texture
->
LockRect
(
0
,
&
locked_rect
,
nullptr
,
D3DLOCK_DISCARD
)
==
D3D_OK
)
{
const
uint8_t
*
src
=
static_cast
(
buffer
)
;
uint8_t
*
dst
=
static_cast
(
locked_rect
.
pBits
)
;
if
(
locked_rect
.
Pitch
==
width
*
4
)
{
memcpy
(
dst
,
src
,
width
*
height
*
4
)
;
}
else
{
for
(
int
y
=
0
;
y
UnlockRect
(
0
)
;
overlay
::
needs_update
=
true
;
}
}
void
overlay
::
create_browser
(
std
::
string url
)
{
if
(
browser_created
)
{
OutputDebugString
(
"created browser"
)
;
}
CefWindowInfo window_info
;
CefBrowserSettings browser_settings
;
browser_settings
.
windowless_frame_rate
=
60
;
browser_settings
.
background_color
=
0x00000000
;
browser_settings
.
webgl
=
STATE_DISABLED
;
window_info
.
SetAsWindowless
(
nullptr
)
;
window_info
.
shared_texture_enabled
=
false
;
window_info
.
external_begin_frame_enabled
=
false
;
CefBrowserHost
::
CreateBrowser
(
window_info
,
cef
,
url
,
browser_settings
,
nullptr
,
nullptr
)
;
browser_created
=
true
;
}
void
overlay
::
initialize
(
)
{
if
(
cef
)
{
OutputDebugString
(
"cef "
)
;
}
CefMainArgs
main_args
(
GetModuleHandle
(
nullptr
)
)
;
CefSettings settings
;
std
::
string work_path
=
std
::
filesystem
::
current_path
(
)
.
string
(
)
;
std
::
filesystem
::
create_directories
(
work_path
+
"\\cef_cache"
)
;
CefString
(
&
settings
.
browser_subprocess_path
)
.
FromString
(
work_path
+
"\\cef_subprocess.exe"
)
;
CefString
(
&
settings
.
cache_path
)
.
FromString
(
work_path
+
"\\cef_cache"
)
;
CefString
(
&
settings
.
locales_dir_path
)
.
FromString
(
work_path
+
"\\locales"
)
;
CefString
(
&
settings
.
resources_dir_path
)
.
FromString
(
work_path
)
;
CefString
(
&
settings
.
locale
)
.
FromString
(
"ru"
)
;
CefString
(
&
settings
.
accept_language_list
)
.
FromString
(
"ru-RU,ru,en-US,en"
)
;
settings
.
windowless_rendering_enabled
=
true
;
settings
.
no_sandbox
=
true
;
settings
.
multi_threaded_message_loop
=
true
;
settings
.
background_color
=
0x00000000
;
settings
.
log_severity
=
LOGSEVERITY_DISABLE
;
settings
.
command_line_args_disabled
=
true
;
if
(
!
CefInitialize
(
main_args
,
settings
,
nullptr
,
nullptr
)
)
{
OutputDebugString
(
"cefinit"
)
;
}
cef
=
new
c_overlay
(
)
;
create_browser
(
)
;
}
int
GetCefModifiers
(
)
{
int
modifiers
=
0
;
if
(
GetKeyState
(
VK_SHIFT
)
&
0x8000
)
modifiers
|=
EVENTFLAG_SHIFT_DOWN
;
if
(
GetKeyState
(
VK_CONTROL
)
&
0x8000
)
modifiers
|=
EVENTFLAG_CONTROL_DOWN
;
if
(
GetKeyState
(
VK_MENU
)
&
0x8000
)
modifiers
|=
EVENTFLAG_ALT_DOWN
;
if
(
GetKeyState
(
VK_CAPITAL
)
&
0x0001
)
modifiers
|=
EVENTFLAG_CAPS_LOCK_ON
;
return
modifiers
;
}
bool
overlay
::
wnd_proc
(
HWND hwnd
,
UINT umsg
,
WPARAM wp
,
LPARAM lp
)
{
if
(
!
cef
||
!
cef
->
GetBrowser
(
)
)
{
OutputDebugString
(
"return false"
)
;
return
false
;
}
CefRefPtr
host
=
cef
->
GetBrowser
(
)
->
GetHost
(
)
;
// обработка мыши
if
(
umsg
>=
WM_MOUSEFIRST
&&
umsg
SendMouseMoveEvent
(
mouse_event
,
false
)
;
return
true
;
case
WM_LBUTTONDOWN
:
host
->
SendMouseClickEvent
(
mouse_event
,
MBT_LEFT
,
false
,
1
)
;
return
true
;
case
WM_LBUTTONUP
:
host
->
SendMouseClickEvent
(
mouse_event
,
MBT_LEFT
,
true
,
1
)
;
return
true
;
case
WM_RBUTTONDOWN
:
host
->
SendMouseClickEvent
(
mouse_event
,
MBT_RIGHT
,
false
,
1
)
;
return
true
;
case
WM_RBUTTONUP
:
host
->
SendMouseClickEvent
(
mouse_event
,
MBT_RIGHT
,
true
,
1
)
;
return
true
;
case
WM_MOUSEWHEEL
:
host
->
SendMouseWheelEvent
(
mouse_event
,
0
,
GET_WHEEL_DELTA_WPARAM
(
wp
)
)
;
return
true
;
}
}
// обработка клавы
if
(
umsg
>=
WM_KEYFIRST
&&
umsg
(
wp
)
;
event
.
native_key_code
=
static_cast
(
lp
)
;
event
.
modifiers
=
GetCefModifiers
(
)
;
if
(
umsg
==
WM_KEYDOWN
||
umsg
==
WM_SYSKEYDOWN
)
{
event
.
type
=
KEYEVENT_RAWKEYDOWN
;
}
else
if
(
umsg
==
WM_KEYUP
||
umsg
==
WM_SYSKEYUP
)
{
event
.
type
=
KEYEVENT_KEYUP
;
}
else
if
(
umsg
==
WM_CHAR
)
{
event
.
type
=
KEYEVENT_CHAR
;
}
// esc
if
(
event
.
windows_key_code
==
VK_ESCAPE
&&
event
.
type
==
KEYEVENT_RAWKEYDOWN
)
{
return
false
;
}
host
->
SendKeyEvent
(
event
)
;
return
true
;
}
return
false
;
}
void
overlay
::
destroy
(
)
{
if
(
texture
)
{
texture
->
Release
(
)
;
texture
=
nullptr
;
}
if
(
cef
)
{
if
(
cef
->
GetBrowser
(
)
)
{
cef
->
GetBrowser
(
)
->
GetHost
(
)
->
CloseBrowser
(
true
)
;
}
delete
cef
;
cef
=
nullptr
;
}
CefShutdown
(
)
;
}
render.cpp:
Код:
#include "render.hpp"
#include "overlay.hpp"
kthook
::
kthook_signal
present_hook
;
kthook
::
kthook_signal
reset_hook
;
std
::
optional
d3d9_present_hooked
(
const
decltype
(
present_hook
)
&
hook
,
IDirect3DDevice9
*
device
,
CONST RECT
*
src_rect
,
CONST RECT
*
dest_rect
,
HWND dest_window
,
CONST RGNDATA
*
dirty_region
)
{
if
(
!
render
::
initialized
)
{
render
::
device
=
device
;
render
::
initialized
=
true
;
}
else
{
for
(
auto
&
f
:
render
::
on_present
)
{
if
(
f
)
f
(
)
;
}
}
return
std
::
nullopt
;
}
std
::
optional
d3d9_lost_hooked
(
const
decltype
(
reset_hook
)
&
hook
,
LPDIRECT3DDEVICE9 device
,
D3DPRESENT_PARAMETERS
*
present_params
)
{
return
std
::
nullopt
;
}
uintptr_t
find_device
(
uint32_t
length
)
{
static
uintptr_t base
=
[
]
(
size_t length
)
{
std
::
string
path
(
MAX_PATH
,
'\0'
)
;
if
(
auto
size
=
GetSystemDirectoryA
(
path
.
data
(
)
,
MAX_PATH
)
)
{
path
.
resize
(
size
)
;
path
+=
"\\d3d9.dll"
;
uintptr_t object_base
=
reinterpret_cast
(
LoadLibraryA
(
path
.
c_str
(
)
)
)
;
while
(
object_base
++
(
object_base
+
0x00
)
==
0x06C7
&&
*
reinterpret_cast
(
object_base
+
0x06
)
==
0x8689
&&
*
reinterpret_cast
(
object_base
+
0x0C
)
==
0x8689
)
{
object_base
+=
2
;
break
;
}
}
return
object_base
;
}
return
uintptr_t
(
0
)
;
}
(
length
)
;
return
base
;
}
void
*
get_function_address
(
int
virtual_table_index
)
{
return
(
*
reinterpret_cast
(
find_device
(
0x128000
)
)
)
[
virtual_table_index
]
;
}
void
render
::
initialize
(
)
{
present_hook
.
set_dest
(
get_function_address
(
17
)
)
;
present_hook
.
install
(
)
;
reset_hook
.
set_dest
(
get_function_address
(
16
)
)
;
reset_hook
.
install
(
)
;
present_hook
.
before
.
connect
(
&
d3d9_present_hooked
)
;
reset_hook
.
before
.
connect
(
&
d3d9_lost_hooked
)
;
}
void
render
::
destroy
(
)
{
}
|