mirror of
https://github.com/Mr-X-GTA/YimMenu.git
synced 2026-10-12 10:18:05 +08:00
feat(invoker): add compiler hints chore(get network event data): added translation TODO feat(native hooks): add compiler hint to crashes feat(render): add likely compiler hint to on_present feat(thread pool): add compiler hints Added hook likely/unlikely switches to debug/crash scenarios. Added HEX_TO_UPPER call on the AC verifier offsets. Added more fuzzer unlikely attributes. Replaced some hard coded numbers with their unhashed _J variants. Added more unlikely attributes to singleton initializer checks. Added more likely/unlikely attributes to certain scenarios.
134 lines
2.7 KiB
C++
134 lines
2.7 KiB
C++
#include "renderer.hpp"
|
|
|
|
#include "file_manager.hpp"
|
|
#include "fonts/fonts.hpp"
|
|
#include "gui.hpp"
|
|
#include "pointers.hpp"
|
|
|
|
#include <backends/imgui_impl_dx11.h>
|
|
#include <backends/imgui_impl_win32.h>
|
|
#include <imgui.h>
|
|
#include <imgui_internal.h>
|
|
|
|
IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
|
|
|
namespace big
|
|
{
|
|
renderer::renderer() :
|
|
m_font_mgr()
|
|
{
|
|
}
|
|
|
|
bool renderer::init()
|
|
{
|
|
if (!g_pointers->m_gta.m_swapchain || !*g_pointers->m_gta.m_swapchain)
|
|
{
|
|
LOG(FATAL) << "Invalid swapchain ptr";
|
|
|
|
return false;
|
|
}
|
|
m_dxgi_swapchain = *g_pointers->m_gta.m_swapchain;
|
|
|
|
if (m_dxgi_swapchain->GetDevice(__uuidof(ID3D11Device), reinterpret_cast<void**>(&m_d3d_device)) < 0)
|
|
{
|
|
LOG(FATAL) << "Failed to get D3D device.";
|
|
|
|
return false;
|
|
}
|
|
m_d3d_device->GetImmediateContext(&m_d3d_device_context);
|
|
|
|
auto file_path = g_file_manager.get_project_file("./imgui.ini").get_path();
|
|
|
|
ImGuiContext* ctx = ImGui::CreateContext();
|
|
|
|
static std::string path = file_path.make_preferred().string();
|
|
ctx->IO.IniFilename = path.c_str();
|
|
|
|
ImGui_ImplDX11_Init(m_d3d_device, m_d3d_device_context);
|
|
ImGui_ImplWin32_Init(g_pointers->m_hwnd);
|
|
|
|
return true;
|
|
}
|
|
|
|
void renderer::destroy()
|
|
{
|
|
ImGui_ImplWin32_Shutdown();
|
|
ImGui_ImplDX11_Shutdown();
|
|
ImGui::DestroyContext();
|
|
}
|
|
|
|
bool renderer::add_dx_callback(dx_callback callback, uint32_t priority)
|
|
{
|
|
if (!m_dx_callbacks.insert({priority, callback}).second)
|
|
{
|
|
LOG(WARNING) << "Duplicate priority given on DX Callback!";
|
|
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
void renderer::add_wndproc_callback(wndproc_callback callback)
|
|
{
|
|
m_wndproc_callbacks.emplace_back(callback);
|
|
}
|
|
|
|
void renderer::on_present()
|
|
{
|
|
if (m_font_mgr.can_use()) [[likely]]
|
|
{
|
|
new_frame();
|
|
for (const auto& cb : m_dx_callbacks | std::views::values)
|
|
cb();
|
|
end_frame();
|
|
|
|
m_font_mgr.release_use();
|
|
}
|
|
}
|
|
|
|
void renderer::rescale(float rel_size)
|
|
{
|
|
pre_reset();
|
|
g_gui->restore_default_style();
|
|
|
|
if (rel_size != 1.0f)
|
|
ImGui::GetStyle().ScaleAllSizes(rel_size);
|
|
|
|
ImGui::GetStyle().MouseCursorScale = 1.0f;
|
|
ImGui::GetIO().FontGlobalScale = rel_size;
|
|
post_reset();
|
|
}
|
|
|
|
void renderer::pre_reset()
|
|
{
|
|
ImGui_ImplDX11_InvalidateDeviceObjects();
|
|
}
|
|
|
|
void renderer::post_reset()
|
|
{
|
|
ImGui_ImplDX11_CreateDeviceObjects();
|
|
}
|
|
|
|
void renderer::wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
|
|
{
|
|
for (const auto& cb : m_wndproc_callbacks)
|
|
cb(hwnd, msg, wparam, lparam);
|
|
|
|
|
|
ImGui_ImplWin32_WndProcHandler(hwnd, msg, wparam, lparam);
|
|
}
|
|
|
|
void renderer::new_frame()
|
|
{
|
|
ImGui_ImplDX11_NewFrame();
|
|
ImGui_ImplWin32_NewFrame();
|
|
ImGui::NewFrame();
|
|
}
|
|
|
|
void renderer::end_frame()
|
|
{
|
|
ImGui::Render();
|
|
ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData());
|
|
}
|
|
}
|