2016-07-31 14:46:22 -04:00
|
|
|
#include "STDInclude.hpp"
|
|
|
|
|
|
|
|
namespace Components
|
|
|
|
{
|
|
|
|
Utils::Hook Renderer::DrawFrameHook;
|
|
|
|
wink::signal<wink::slot<Renderer::Callback>> Renderer::FrameSignal;
|
|
|
|
wink::signal<wink::slot<Renderer::Callback>> Renderer::FrameOnceSignal;
|
|
|
|
wink::signal<wink::slot<Renderer::BackendCallback>> Renderer::BackendFrameSignal;
|
|
|
|
|
2016-09-13 14:55:10 -04:00
|
|
|
wink::signal<wink::slot<Renderer::Callback>> Renderer::EndRecoverDeviceSignal;
|
|
|
|
wink::signal<wink::slot<Renderer::Callback>> Renderer::BeginRecoverDeviceSignal;
|
|
|
|
|
2016-08-07 19:57:00 -04:00
|
|
|
__declspec(naked) void Renderer::FrameStub()
|
2016-07-31 14:46:22 -04:00
|
|
|
{
|
|
|
|
__asm
|
|
|
|
{
|
|
|
|
call Renderer::FrameHandler
|
2016-11-20 08:09:07 -05:00
|
|
|
jmp Renderer::DrawFrameHook.original
|
2016-07-31 14:46:22 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::FrameHandler()
|
|
|
|
{
|
2016-10-02 19:36:18 -04:00
|
|
|
auto copy = Renderer::FrameSignal;
|
|
|
|
copy();
|
|
|
|
|
|
|
|
copy = Renderer::FrameOnceSignal;
|
2016-07-31 14:46:22 -04:00
|
|
|
Renderer::FrameOnceSignal.clear();
|
2016-10-02 19:36:18 -04:00
|
|
|
copy();
|
2016-07-31 14:46:22 -04:00
|
|
|
}
|
|
|
|
|
2016-08-07 19:57:00 -04:00
|
|
|
__declspec(naked) void Renderer::BackendFrameStub()
|
2016-07-31 14:46:22 -04:00
|
|
|
{
|
|
|
|
__asm
|
|
|
|
{
|
|
|
|
call Renderer::BackendFrameHandler
|
|
|
|
|
|
|
|
mov eax, ds:66E1BF0h
|
|
|
|
mov ecx, 536A85h
|
|
|
|
jmp ecx
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::BackendFrameHandler()
|
|
|
|
{
|
|
|
|
IDirect3DDevice9* device = *Game::dx_ptr;
|
|
|
|
|
|
|
|
if (device)
|
|
|
|
{
|
|
|
|
device->AddRef();
|
|
|
|
Renderer::BackendFrameSignal(device);
|
|
|
|
device->Release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::Once(Renderer::Callback* callback)
|
|
|
|
{
|
|
|
|
Renderer::FrameOnceSignal.connect(callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::OnFrame(Renderer::Callback* callback)
|
|
|
|
{
|
|
|
|
Renderer::FrameSignal.connect(callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::OnBackendFrame(Renderer::BackendCallback* callback)
|
|
|
|
{
|
|
|
|
Renderer::BackendFrameSignal.connect(callback);
|
|
|
|
}
|
|
|
|
|
2016-09-13 14:55:10 -04:00
|
|
|
void Renderer::OnDeviceRecoveryEnd(Renderer::Callback* callback)
|
|
|
|
{
|
|
|
|
Renderer::EndRecoverDeviceSignal.connect(callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::OnDeviceRecoveryBegin(Renderer::Callback* callback)
|
|
|
|
{
|
|
|
|
Renderer::BeginRecoverDeviceSignal.connect(callback);
|
|
|
|
}
|
|
|
|
|
2016-07-31 14:46:22 -04:00
|
|
|
int Renderer::Width()
|
|
|
|
{
|
|
|
|
return Utils::Hook::Get<int>(0x66E1C68);
|
|
|
|
}
|
|
|
|
|
|
|
|
int Renderer::Height()
|
|
|
|
{
|
|
|
|
return Utils::Hook::Get<int>(0x66E1C6C);
|
|
|
|
}
|
|
|
|
|
|
|
|
Renderer::Renderer()
|
|
|
|
{
|
|
|
|
// Renderer::OnBackendFrame([] (IDirect3DDevice9* device)
|
|
|
|
// {
|
|
|
|
// if (Game::Sys_Milliseconds() % 2)
|
|
|
|
// {
|
|
|
|
// device->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER | D3DCLEAR_STENCIL, 0, 0, 0);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// return;
|
|
|
|
//
|
|
|
|
// IDirect3DSurface9* buffer = nullptr;
|
|
|
|
//
|
|
|
|
// device->CreateOffscreenPlainSurface(Renderer::Width(), Renderer::Height(), D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &buffer, nullptr);
|
|
|
|
// device->GetFrontBufferData(0, buffer);
|
|
|
|
//
|
|
|
|
// if (buffer)
|
|
|
|
// {
|
|
|
|
// D3DSURFACE_DESC desc;
|
|
|
|
// D3DLOCKED_RECT lockedRect;
|
|
|
|
//
|
|
|
|
// buffer->GetDesc(&desc);
|
|
|
|
//
|
|
|
|
// HRESULT res = buffer->LockRect(&lockedRect, NULL, D3DLOCK_READONLY);
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// buffer->UnlockRect();
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
|
|
|
|
// Frame hook
|
2016-11-20 08:09:07 -05:00
|
|
|
Renderer::DrawFrameHook.initialize(0x5ACB99, Renderer::FrameStub, HOOK_CALL)->install();
|
2016-07-31 14:46:22 -04:00
|
|
|
|
2016-11-20 08:09:07 -05:00
|
|
|
Utils::Hook(0x536A80, Renderer::BackendFrameStub, HOOK_JUMP).install()->quick();
|
2016-09-13 14:55:10 -04:00
|
|
|
|
|
|
|
Utils::Hook(0x508298, [] ()
|
|
|
|
{
|
|
|
|
Game::DB_BeginRecoverLostDevice();
|
|
|
|
Renderer::BeginRecoverDeviceSignal();
|
2016-11-20 08:09:07 -05:00
|
|
|
}, HOOK_CALL).install()->quick();
|
2016-09-13 14:55:10 -04:00
|
|
|
|
|
|
|
Utils::Hook(0x508355, [] ()
|
|
|
|
{
|
|
|
|
Renderer::EndRecoverDeviceSignal();
|
|
|
|
Game::DB_EndRecoverLostDevice();
|
2016-11-20 08:09:07 -05:00
|
|
|
}, HOOK_CALL).install()->quick();
|
2016-07-31 14:46:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
Renderer::~Renderer()
|
|
|
|
{
|
2016-11-20 08:09:07 -05:00
|
|
|
Renderer::DrawFrameHook.uninstall();
|
2016-07-31 14:46:22 -04:00
|
|
|
Renderer::BackendFrameSignal.clear();
|
|
|
|
Renderer::FrameOnceSignal.clear();
|
|
|
|
Renderer::FrameSignal.clear();
|
2016-09-13 14:55:10 -04:00
|
|
|
|
|
|
|
Renderer::EndRecoverDeviceSignal.clear();
|
|
|
|
Renderer::BeginRecoverDeviceSignal.clear();
|
2016-07-31 14:46:22 -04:00
|
|
|
}
|
|
|
|
}
|