diff --git a/src/dllmain.cpp b/src/dllmain.cpp index a6acd27..f7c2076 100644 --- a/src/dllmain.cpp +++ b/src/dllmain.cpp @@ -75,7 +75,7 @@ void ImGuiThread(void* param) { } } - if (!Hook::Inject(&ScriptExData::DrawFrames)) { + if (!Hook::Inject(&ScriptExData::RenderFrames)) { MessageBox(HWND_DESKTOP, "Failed to inject dxhook..", "ImGuiRedux", MB_ICONERROR); } diff --git a/src/hook.cpp b/src/hook.cpp index 8e3fad3..46abbcf 100644 --- a/src/hook.cpp +++ b/src/hook.cpp @@ -140,6 +140,8 @@ void Hook::ProcessFrame(void* ptr) { ScriptExData::SetScaling({scaleX, scaleY}); } + ScriptExData::InitRenderStates(); + ImGui_ImplWin32_NewFrame(); if (gRenderer == eRenderer::Dx9) { ImGui_ImplDX9_NewFrame(); diff --git a/src/imguiframe.hpp b/src/imguiframe.hpp new file mode 100644 index 0000000..6763f74 --- /dev/null +++ b/src/imguiframe.hpp @@ -0,0 +1,109 @@ +#pragma once +#include "imgui.h" +#include +#include +#include + +extern enum class eGameVer; +extern eGameVer gGameVer; + +struct FontInfo { + bool m_bFontLoaded = false; + ImFont *m_pFont = nullptr; + std::string m_Path; + float m_nSize = 14.0f; + size_t m_nStart, m_nEnd; +}; + +class ImGuiFrame { +public: + ImGuiContext *m_pContext = nullptr; + + // Scaling related + ImVec2 m_vecScaling = ImVec2(1, 1); + bool m_bWasScalingUpdatedThisFrame; + bool m_bNeedToUpdateScaling; + long long m_nLastScriptCallMS; + + // Render buffers + bool m_bIsBackBufferReady; + std::vector> m_RenderBuffer, m_BackBuffer; + + // for ImGui::ImageButton() + ImVec4 m_vecImgTint = ImVec4(1, 1, 1, 1); + ImVec4 m_vecImgBgCol = ImVec4(1, 1, 1, 1); + + // Fonts + std::vector> m_FontGlyphRange; + std::vector m_FontTable; + + ImGuiFrame() { + // m_pContext = ImGui::CreateContext(); + } + + ImGuiFrame& operator+=(std::function f) { + if (!m_bIsBackBufferReady) { + m_BackBuffer.push_back(f); + } + return *this; + } + + void BeforeRender() { + // bool buildRequired = false; + // for (auto& e: m_FontTable) { + // if (!e.m_bFontLoaded) { + // ImWchar ranges[] = { + // e.m_nStart, e.m_nEnd, 0 + // }; + // ImGui::GetIO().Fonts->AddFontFromFileTTF(e.m_Path.c_str(), e.m_nSize, NULL, ranges); + // buildRequired = true; + // } + // } + + // if (buildRequired) { + // ImGui::GetIO().Fonts->Build(); + // } + } + + void OnRender() { + for (auto func : m_RenderBuffer) { + func(); + } + + // if back buffer is render ready switch the buffer and reset render state + if (m_bIsBackBufferReady) { + m_RenderBuffer = std::move(m_BackBuffer); + m_bIsBackBufferReady = false; + } + + time_t curTime = time(NULL); + // Clear buffer when script stops responding + bool scriptsPaused = false; + switch(static_cast(gGameVer)) { + case 0: // III + scriptsPaused = *(bool*)0x95CD7C; + break; + case 1: // VC + scriptsPaused = *(bool*)0xA10B36; + break; + case 2: // SA + scriptsPaused = *(bool*)0xB7CB49; + break; + default: + break; + } + + if (curTime-m_nLastScriptCallMS > 2 || scriptsPaused) { + OnClear(); + } + + if (m_bWasScalingUpdatedThisFrame) { + m_bNeedToUpdateScaling = false; + m_bWasScalingUpdatedThisFrame = false; + } + } + + void OnClear() { + m_RenderBuffer.clear(); + } +}; \ No newline at end of file diff --git a/src/opcodemgr.cpp b/src/opcodemgr.cpp index b23353a..ac08b2d 100644 --- a/src/opcodemgr.cpp +++ b/src/opcodemgr.cpp @@ -23,21 +23,21 @@ static RTN_TYPE RUNTIME_API ImGuiBegin(RUNTIME_CONTEXT ctx) { if (autoResize) flags |= ImGuiWindowFlags_AlwaysAutoResize; ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { bool isOpen = openFlag; if (isOpen) { ImGui::Begin(label, &isOpen, flags); data->SetData(label, 0, isOpen); } }; - data->imgui.lastScriptCall = time(NULL); + data->m_ImGuiData.m_nLastScriptCallMS = time(NULL); wSetIntParam(ctx, data->GetData(label, 0, true)); return RTN_CONTINUE; } static RTN_TYPE RUNTIME_API ImGuiEnd(RUNTIME_CONTEXT ctx) { ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { ImGui::End(); }; return RTN_CONTINUE; @@ -52,7 +52,7 @@ static RTN_TYPE RUNTIME_API ImGuiButton(RUNTIME_CONTEXT ctx) { size.y = wGetFloatParam(ctx); ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { bool isPressed = ImGui::Button(buf, ImVec2(size.x, size.y)); data->SetData(buf, 0, isPressed); }; @@ -79,10 +79,11 @@ static RTN_TYPE RUNTIME_API ImGuiImageButton(RUNTIME_CONTEXT ctx) { } ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { ImGui::PushID(buf); const ImGuiID id = ImGui::GetID(buf); - bool isPressed = ImGui::ImageButtonEx(id, pInfo->pTexture, size, {0.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 0.0f}, data->imgui.m_ImGCol.m_fBgCol, data->imgui.m_ImGCol.m_fTintCol); + bool isPressed = ImGui::ImageButtonEx(id, pInfo->pTexture, size, {0.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 0.0f}, + data->m_ImGuiData.m_vecImgBgCol, data->m_ImGuiData.m_vecImgTint); ImGui::PopID(); data->SetData(buf, 0, isPressed); }; @@ -99,7 +100,7 @@ static RTN_TYPE RUNTIME_API ImGuiSetImageTintColor(RUNTIME_CONTEXT ctx) { col.z = wGetFloatParam(ctx); col.w = wGetFloatParam(ctx); ScriptExData* data = ScriptExData::Get(); - data->imgui.m_ImGCol.m_fTintCol = col; + data->m_ImGuiData.m_vecImgTint = col; return RTN_CONTINUE; } @@ -111,7 +112,7 @@ static RTN_TYPE RUNTIME_API ImGuiSetImageBgColor(RUNTIME_CONTEXT ctx) { col.z = wGetFloatParam(ctx); col.w = wGetFloatParam(ctx); ScriptExData* data = ScriptExData::Get(); - data->imgui.m_ImGCol.m_fBgCol = col; + data->m_ImGuiData.m_vecImgBgCol = col; return RTN_CONTINUE; } @@ -140,7 +141,7 @@ static RTN_TYPE RUNTIME_API ImGuiArrowButton(RUNTIME_CONTEXT ctx) { } ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { bool isPressed = ImGui::ArrowButton(buf, side); data->SetData(buf, 0, isPressed); }; @@ -159,7 +160,7 @@ static RTN_TYPE RUNTIME_API ImGuiInvisibleButton(RUNTIME_CONTEXT ctx) { size.y = wGetFloatParam(ctx); ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { bool isPressed = ImGui::InvisibleButton(buf, ImVec2(size.x, size.y)); data->SetData(buf, 0, isPressed); }; @@ -184,7 +185,7 @@ static RTN_TYPE RUNTIME_API ImGuiColorButton(RUNTIME_CONTEXT ctx) { size.y = wGetFloatParam(ctx); ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { bool isPressed = ImGui::ColorButton(buf, rgba, NULL, ImVec2(size.x, size.y)); data->SetData(buf, 0, isPressed); }; @@ -200,7 +201,7 @@ static RTN_TYPE RUNTIME_API ImGuiCheckbox(RUNTIME_CONTEXT ctx) { bool state = wGetBoolParam(ctx); ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { bool check = state; bool clicked = ImGui::Checkbox(buf, &check); @@ -218,7 +219,7 @@ static RTN_TYPE RUNTIME_API ImGuiCheckbox(RUNTIME_CONTEXT ctx) { static RTN_TYPE RUNTIME_API ImGuiSameLine(RUNTIME_CONTEXT ctx) { ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { ImGui::SameLine(); }; return RTN_CONTINUE; @@ -226,7 +227,7 @@ static RTN_TYPE RUNTIME_API ImGuiSameLine(RUNTIME_CONTEXT ctx) { static RTN_TYPE RUNTIME_API ImGuiNewLine(RUNTIME_CONTEXT ctx) { ScriptExData* data = ScriptExData::Get(); - data->imgui += []() { + data->m_ImGuiData += []() { ImGui::NewLine(); }; return RTN_CONTINUE; @@ -236,7 +237,7 @@ static RTN_TYPE RUNTIME_API ImGuiColumns(RUNTIME_CONTEXT ctx) { int count = wGetIntParam(ctx); count = max(count, 1); ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { ImGui::Columns(count, NULL, false); }; return RTN_CONTINUE; @@ -246,11 +247,11 @@ static RTN_TYPE RUNTIME_API ImGuiSetColumnWidth(RUNTIME_CONTEXT ctx) { int idx = wGetIntParam(ctx); float width = wGetFloatParam(ctx); ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { - ImGui::SetColumnWidth(idx, width * data->imgui.m_vecScaling.x); + data->m_ImGuiData += [=]() { + ImGui::SetColumnWidth(idx, width * data->m_ImGuiData.m_vecScaling.x); - if (data->imgui.m_bNeedToUpdateScaling) { - data->imgui.m_bWasScalingUpdatedThisFrame = true; + if (data->m_ImGuiData.m_bNeedToUpdateScaling) { + data->m_ImGuiData.m_bWasScalingUpdatedThisFrame = true; } }; @@ -259,7 +260,7 @@ static RTN_TYPE RUNTIME_API ImGuiSetColumnWidth(RUNTIME_CONTEXT ctx) { static RTN_TYPE RUNTIME_API ImGuiNextColumn(RUNTIME_CONTEXT ctx) { ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { ImGui::NextColumn(); }; return RTN_CONTINUE; @@ -267,7 +268,7 @@ static RTN_TYPE RUNTIME_API ImGuiNextColumn(RUNTIME_CONTEXT ctx) { static RTN_TYPE RUNTIME_API ImGuiSpacing(RUNTIME_CONTEXT ctx) { ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { ImGui::Spacing(); }; return RTN_CONTINUE; @@ -275,7 +276,7 @@ static RTN_TYPE RUNTIME_API ImGuiSpacing(RUNTIME_CONTEXT ctx) { static RTN_TYPE RUNTIME_API ImGuiSeparator(RUNTIME_CONTEXT ctx) { ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { ImGui::Separator(); }; return RTN_CONTINUE; @@ -303,7 +304,7 @@ static RTN_TYPE RUNTIME_API ImGuiSetNextWindowPos(RUNTIME_CONTEXT ctx) { int cond = wGetIntParam(ctx); ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { ImGui::SetNextWindowPos(pos, cond); }; @@ -314,7 +315,7 @@ static RTN_TYPE RUNTIME_API ImGuiSetNextWindowTransparency(RUNTIME_CONTEXT ctx) float alpha = wGetFloatParam(ctx); ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { ImGui::SetNextWindowBgAlpha(alpha); }; @@ -328,7 +329,7 @@ static RTN_TYPE RUNTIME_API ImGuiSetWindowPos(RUNTIME_CONTEXT ctx) { int cond = wGetIntParam(ctx); ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { ImGui::SetWindowPos(pos, cond); }; @@ -342,12 +343,12 @@ static RTN_TYPE RUNTIME_API ImGuiSetNextWindowSize(RUNTIME_CONTEXT ctx) { int cond = wGetIntParam(ctx); ScriptExData* data = ScriptExData::Get(); - cond = data->imgui.m_bNeedToUpdateScaling ? ImGuiCond_Always : cond; - data->imgui += [=]() { - ImGui::SetNextWindowSize({size.x * data->imgui.m_vecScaling.x, size.y * data->imgui.m_vecScaling.y}, cond); + cond = data->m_ImGuiData.m_bNeedToUpdateScaling ? ImGuiCond_Always : cond; + data->m_ImGuiData += [=]() { + ImGui::SetNextWindowSize({size.x * data->m_ImGuiData.m_vecScaling.x, size.y * data->m_ImGuiData.m_vecScaling.y}, cond); - if (data->imgui.m_bNeedToUpdateScaling) { - data->imgui.m_bWasScalingUpdatedThisFrame = true; + if (data->m_ImGuiData.m_bNeedToUpdateScaling) { + data->m_ImGuiData.m_bWasScalingUpdatedThisFrame = true; } }; @@ -361,12 +362,12 @@ static RTN_TYPE RUNTIME_API ImGuiSetWindowSize(RUNTIME_CONTEXT ctx) { int cond = wGetIntParam(ctx); ScriptExData* data = ScriptExData::Get(); - cond = data->imgui.m_bNeedToUpdateScaling ? ImGuiCond_Always : cond; - data->imgui += [=]() { - ImGui::SetWindowSize({size.x * data->imgui.m_vecScaling.x, size.y * data->imgui.m_vecScaling.y}, cond); + cond = data->m_ImGuiData.m_bNeedToUpdateScaling ? ImGuiCond_Always : cond; + data->m_ImGuiData += [=]() { + ImGui::SetWindowSize({size.x * data->m_ImGuiData.m_vecScaling.x, size.y * data->m_ImGuiData.m_vecScaling.y}, cond); - if (data->imgui.m_bNeedToUpdateScaling) { - data->imgui.m_bWasScalingUpdatedThisFrame = true; + if (data->m_ImGuiData.m_bNeedToUpdateScaling) { + data->m_ImGuiData.m_bWasScalingUpdatedThisFrame = true; } }; @@ -379,7 +380,7 @@ static RTN_TYPE RUNTIME_API ImGuiDummy(RUNTIME_CONTEXT ctx) { size.y = wGetFloatParam(ctx); ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { ImGui::Dummy(size); }; @@ -391,7 +392,7 @@ static RTN_TYPE RUNTIME_API ImGuiText(RUNTIME_CONTEXT ctx) { wGetStringParam(ctx, buf, RUNTIME_STR_LEN); ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { ImGui::TextUnformatted(buf); }; return RTN_CONTINUE; @@ -402,7 +403,7 @@ static RTN_TYPE RUNTIME_API ImGuiTextCentered(RUNTIME_CONTEXT ctx) { wGetStringParam(ctx, buf, RUNTIME_STR_LEN); ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { ImGui::NewLine(); ImVec2 size = ImGui::CalcTextSize(buf); float width = ImGui::GetWindowContentRegionWidth() - size.x; @@ -417,7 +418,7 @@ static RTN_TYPE RUNTIME_API ImGuiTextDisabled(RUNTIME_CONTEXT ctx) { wGetStringParam(ctx, buf, RUNTIME_STR_LEN); ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { ImGui::TextDisabled(buf); }; return RTN_CONTINUE; @@ -428,7 +429,7 @@ static RTN_TYPE RUNTIME_API ImGuiTextWrapped(RUNTIME_CONTEXT ctx) { wGetStringParam(ctx, buf, RUNTIME_STR_LEN); ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { ImGui::TextWrapped(buf); }; return RTN_CONTINUE; @@ -439,7 +440,7 @@ static RTN_TYPE RUNTIME_API ImGuiBulletText(RUNTIME_CONTEXT ctx) { wGetStringParam(ctx, buf, RUNTIME_STR_LEN); ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { ImGui::BulletText(buf); }; return RTN_CONTINUE; @@ -455,7 +456,7 @@ static RTN_TYPE RUNTIME_API ImGuiTextColored(RUNTIME_CONTEXT ctx) { col.w = wGetFloatParam(ctx); ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { ImGui::TextColored(col, buf); }; return RTN_CONTINUE; @@ -466,7 +467,7 @@ static RTN_TYPE RUNTIME_API ImGuiSetTooltip(RUNTIME_CONTEXT ctx) { wGetStringParam(ctx, buf, RUNTIME_STR_LEN); ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { ImGui::SetTooltip(buf); }; return RTN_CONTINUE; @@ -479,7 +480,7 @@ static RTN_TYPE RUNTIME_API ImGuiSetCursorVisible(RUNTIME_CONTEXT ctx) { // Hidden by default if (flag) { ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { data->SetCursorVisible(flag); }; } @@ -489,11 +490,11 @@ static RTN_TYPE RUNTIME_API ImGuiSetCursorVisible(RUNTIME_CONTEXT ctx) { static RTN_TYPE RUNTIME_API ImGuiGetFrameHeight(RUNTIME_CONTEXT ctx) { ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { - data->SetData("__frameHeight__", 0, ImGui::GetFrameHeight() / data->imgui.m_vecScaling.y); + data->m_ImGuiData += [=]() { + data->SetData("__frameHeight__", 0, ImGui::GetFrameHeight() / data->m_ImGuiData.m_vecScaling.y); - if (data->imgui.m_bNeedToUpdateScaling) { - data->imgui.m_bWasScalingUpdatedThisFrame = true; + if (data->m_ImGuiData.m_bNeedToUpdateScaling) { + data->m_ImGuiData.m_bWasScalingUpdatedThisFrame = true; } }; wSetFloatParam(ctx, data->GetData("__frameHeight__", 0, 0.0f)); @@ -505,10 +506,10 @@ static RTN_TYPE RUNTIME_API ImGuiGetWindowSize(RUNTIME_CONTEXT ctx) { wGetStringWithFrame(ctx, buf, RUNTIME_STR_LEN); ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { ImVec2 size = ImGui::GetWindowSize(); - data->SetData(buf, 0, size.x / data->imgui.m_vecScaling.x); - data->SetData(buf, 1, size.y / data->imgui.m_vecScaling.y); + data->SetData(buf, 0, size.x / data->m_ImGuiData.m_vecScaling.x); + data->SetData(buf, 1, size.y / data->m_ImGuiData.m_vecScaling.y); }; ImVec2 size = { data->GetData(buf, 0, 0.0f), data->GetData(buf, 1, 0.0f) }; @@ -532,7 +533,7 @@ static RTN_TYPE RUNTIME_API ImGuiGetWindowPos(RUNTIME_CONTEXT ctx) { wGetStringWithFrame(ctx, buf, RUNTIME_STR_LEN); ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { ImVec2 pos = ImGui::GetWindowPos(); data->SetData(buf, 0, pos.x); data->SetData(buf, 1, pos.y); @@ -549,7 +550,7 @@ static RTN_TYPE RUNTIME_API ImGuiCalcTextSize(RUNTIME_CONTEXT ctx) { wGetStringWithFrame(ctx, buf, RUNTIME_STR_LEN); ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { ImVec2 size = ImGui::CalcTextSize(buf); data->SetData(buf, 0, size.x); data->SetData(buf, 1, size.y); @@ -566,12 +567,12 @@ static RTN_TYPE RUNTIME_API ImGuiGetWindowContentRegionWidth(RUNTIME_CONTEXT ctx wGetStringWithFrame(ctx, buf, RUNTIME_STR_LEN); ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { float width = ImGui::GetWindowContentRegionWidth(); - data->SetData(buf, 0, width / data->imgui.m_vecScaling.x); + data->SetData(buf, 0, width / data->m_ImGuiData.m_vecScaling.x); - if (data->imgui.m_bNeedToUpdateScaling) { - data->imgui.m_bWasScalingUpdatedThisFrame = true; + if (data->m_ImGuiData.m_bNeedToUpdateScaling) { + data->m_ImGuiData.m_bWasScalingUpdatedThisFrame = true; } }; @@ -584,7 +585,7 @@ static RTN_TYPE RUNTIME_API ImGuiBeginMainMenuBar(RUNTIME_CONTEXT ctx) { wGetStringWithFrame(ctx, buf, RUNTIME_STR_LEN); ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { bool state = ImGui::BeginMainMenuBar(); data->SetData(buf, 0, state); }; @@ -597,7 +598,7 @@ static RTN_TYPE RUNTIME_API ImGuiBeginDisabled(RUNTIME_CONTEXT ctx) { bool flag = wGetIntParam(ctx); ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { ImGui::BeginDisabled(flag); }; @@ -606,7 +607,7 @@ static RTN_TYPE RUNTIME_API ImGuiBeginDisabled(RUNTIME_CONTEXT ctx) { static RTN_TYPE RUNTIME_API ImGuiEndDisabled(RUNTIME_CONTEXT ctx) { ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { ImGui::EndDisabled(); }; return RTN_CONTINUE; @@ -618,7 +619,7 @@ static RTN_TYPE RUNTIME_API ImGuiBeginMenu(RUNTIME_CONTEXT ctx) { bool enabled = wGetIntParam(ctx); ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { bool state = ImGui::BeginMenu(buf, enabled); data->SetData(buf, 0, state); }; @@ -628,7 +629,7 @@ static RTN_TYPE RUNTIME_API ImGuiBeginMenu(RUNTIME_CONTEXT ctx) { static RTN_TYPE RUNTIME_API ImGuiEndMenu(RUNTIME_CONTEXT ctx) { ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { ImGui::EndMenu(); }; return RTN_CONTINUE; @@ -636,7 +637,7 @@ static RTN_TYPE RUNTIME_API ImGuiEndMenu(RUNTIME_CONTEXT ctx) { static RTN_TYPE RUNTIME_API ImGuiEndMainMenuBar(RUNTIME_CONTEXT ctx) { ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { ImGui::EndMainMenuBar(); }; @@ -650,7 +651,7 @@ static RTN_TYPE RUNTIME_API ImGuiMenuItem(RUNTIME_CONTEXT ctx) { bool enabled = wGetBoolParam(ctx); ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { bool state = ImGui::MenuItem(buf, NULL, selected, enabled); data->SetData(buf, 0, state); }; @@ -665,7 +666,7 @@ static RTN_TYPE RUNTIME_API ImGuiSelectable(RUNTIME_CONTEXT ctx) { bool selected = wGetBoolParam(ctx); ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { bool state = ImGui::Selectable(buf, &selected); data->SetData(buf, 0, state); }; @@ -679,7 +680,7 @@ static RTN_TYPE RUNTIME_API ImGuiBeginChild(RUNTIME_CONTEXT ctx) { wGetStringWithFrame(ctx, buf, RUNTIME_STR_LEN); ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { ImGui::BeginChild(buf); }; @@ -698,7 +699,7 @@ static RTN_TYPE RUNTIME_API ImGuiBeginChildEx(RUNTIME_CONTEXT ctx) { flags = wGetIntParam(ctx); ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { ImGui::BeginChild(buf, {szX, szY}, border, flags); }; @@ -707,7 +708,7 @@ static RTN_TYPE RUNTIME_API ImGuiBeginChildEx(RUNTIME_CONTEXT ctx) { static RTN_TYPE RUNTIME_API ImGuiEndChild(RUNTIME_CONTEXT ctx) { ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { ImGui::EndChild(); }; @@ -719,10 +720,10 @@ static RTN_TYPE RUNTIME_API ImGuiPushItemWidth(RUNTIME_CONTEXT ctx) { float width = wGetFloatParam(ctx); ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { - ImGui::PushItemWidth(width * data->imgui.m_vecScaling.x); - if (data->imgui.m_bNeedToUpdateScaling) { - data->imgui.m_bWasScalingUpdatedThisFrame = true; + data->m_ImGuiData += [=]() { + ImGui::PushItemWidth(width * data->m_ImGuiData.m_vecScaling.x); + if (data->m_ImGuiData.m_bNeedToUpdateScaling) { + data->m_ImGuiData.m_bWasScalingUpdatedThisFrame = true; } }; @@ -731,7 +732,7 @@ static RTN_TYPE RUNTIME_API ImGuiPushItemWidth(RUNTIME_CONTEXT ctx) { static RTN_TYPE RUNTIME_API ImGuiPopItemWidth(RUNTIME_CONTEXT ctx) { ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { ImGui::PopItemWidth(); }; @@ -743,7 +744,7 @@ static RTN_TYPE RUNTIME_API ImGuiCollapsingHeader(RUNTIME_CONTEXT ctx) { wGetStringWithFrame(ctx, buf, RUNTIME_STR_LEN); ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { bool state = ImGui::CollapsingHeader(buf); data->SetData(buf, 0, state); }; @@ -793,7 +794,7 @@ static RTN_TYPE RUNTIME_API ImGuiSliderInt(RUNTIME_CONTEXT ctx) { int max = wGetIntParam(ctx); ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { int value = data->GetData(buf, 0, initVal); ImGui::SliderInt(buf, &value, min, max); data->SetData(buf, 0, value); @@ -812,7 +813,7 @@ static RTN_TYPE RUNTIME_API ImGuiSliderFloat(RUNTIME_CONTEXT ctx) { float max = wGetFloatParam(ctx); ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { float value = data->GetData(buf, 0, initVal); ImGui::SliderFloat(buf, &value, min, max); data->SetData(buf, 0, value); @@ -831,7 +832,7 @@ static RTN_TYPE RUNTIME_API ImGuiInputFloat(RUNTIME_CONTEXT ctx) { float max = wGetFloatParam(ctx); ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { float value = data->GetData(buf, 0, initVal); if (ImGui::InputFloat(buf, &value)) { if (value < min) { @@ -859,7 +860,7 @@ static RTN_TYPE RUNTIME_API ImGuiInputInt(RUNTIME_CONTEXT ctx) { int max = wGetIntParam(ctx); ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { int value = data->GetData(buf, 0, initVal); if (ImGui::InputInt(buf, &value)) { if (value < min) { @@ -884,7 +885,7 @@ static RTN_TYPE RUNTIME_API ImGuiInputText(RUNTIME_CONTEXT ctx) { wGetStringWithFrame(ctx, buf, RUNTIME_STR_LEN); ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { std::string str = data->GetData(buf, 0, std::string("")); if (ImGui::InputText(buf, &str)) { data->SetData(buf, 0, str); @@ -901,7 +902,7 @@ static RTN_TYPE RUNTIME_API ImGuiColorPicker(RUNTIME_CONTEXT ctx) { wGetStringWithFrame(ctx, buf, RUNTIME_STR_LEN); ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { float col[4]; col[0] = data->GetData(buf, 0, 0) / 255.0f; col[1] = data->GetData(buf, 1, 0) / 255.0f; @@ -936,7 +937,7 @@ static RTN_TYPE RUNTIME_API ImGuiRadioButton(RUNTIME_CONTEXT ctx) { ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { int value = curSelectedBtn; bool clicked = ImGui::RadioButton(buf, &value, btnNo); data->SetData(buf, 0, clicked); @@ -964,13 +965,13 @@ static RTN_TYPE RUNTIME_API ImGuiBeginFrame(RUNTIME_CONTEXT ctx) { wGetStringWithFrame(ctx, buf, RUNTIME_STR_LEN); ScriptExData::SetCurrentScript(std::string(buf)); ScriptExData *data = ScriptExData::Get(); - + // ImGui::SetCurrentContext(data->m_ImGuiData.m_pContext); return RTN_CONTINUE; } static RTN_TYPE RUNTIME_API ImGuiEndFrame(RUNTIME_CONTEXT ctx) { ScriptExData* data = ScriptExData::Get(); - data->imgui.m_bRender = true; + data->m_ImGuiData.m_bIsBackBufferReady = true; ScriptExData::SetCurrentScript(""); return RTN_CONTINUE; @@ -994,7 +995,7 @@ static RTN_TYPE RUNTIME_API ImGuiCombo(RUNTIME_CONTEXT ctx) { int selectedOption = wGetIntParam(ctx); ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { int value = selectedOption; bool clicked = ImGui::Combo(buf, &value, options); data->SetData(buf, 0, clicked); @@ -1022,7 +1023,7 @@ static RTN_TYPE RUNTIME_API ImGuiIsItemActive(RUNTIME_CONTEXT ctx) { wGetStringWithFrame(ctx, buf, RUNTIME_STR_LEN); ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { data->SetData(buf, 0, ImGui::IsItemActive()); }; @@ -1035,7 +1036,7 @@ static RTN_TYPE RUNTIME_API ImGuiIsItemHovered(RUNTIME_CONTEXT ctx) { wGetStringWithFrame(ctx, buf, RUNTIME_STR_LEN); ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { data->SetData(buf, 0, ImGui::IsItemHovered()); }; @@ -1048,7 +1049,7 @@ static RTN_TYPE RUNTIME_API ImGuiIsItemClicked(RUNTIME_CONTEXT ctx) { wGetStringWithFrame(ctx, buf, RUNTIME_STR_LEN); ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { data->SetData(buf, 0, ImGui::IsItemClicked()); }; @@ -1061,7 +1062,7 @@ static RTN_TYPE RUNTIME_API ImGuiIsItemFocused(RUNTIME_CONTEXT ctx) { wGetStringWithFrame(ctx, buf, RUNTIME_STR_LEN); ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { data->SetData(buf, 0, ImGui::IsItemFocused()); }; @@ -1071,7 +1072,7 @@ static RTN_TYPE RUNTIME_API ImGuiIsItemFocused(RUNTIME_CONTEXT ctx) { static RTN_TYPE RUNTIME_API ImGuiBullet(RUNTIME_CONTEXT ctx) { ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { ImGui::Bullet(); }; return RTN_CONTINUE; @@ -1117,7 +1118,7 @@ static RTN_TYPE RUNTIME_API ImGuiGetScalingSize(RUNTIME_CONTEXT ctx) { int spacing = wGetIntParam(ctx); ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { bool spcaing_ = spacing; if (count == 1) { spcaing_ = false; @@ -1138,11 +1139,11 @@ static RTN_TYPE RUNTIME_API ImGuiGetScalingSize(RUNTIME_CONTEXT ctx) { y = ImGui::GetFrameHeight() * 1.3f; - data->SetData(buf, 0, x / data->imgui.m_vecScaling.x); - data->SetData(buf, 1, y / data->imgui.m_vecScaling.y); + data->SetData(buf, 0, x / data->m_ImGuiData.m_vecScaling.x); + data->SetData(buf, 1, y / data->m_ImGuiData.m_vecScaling.y); - if (data->imgui.m_bNeedToUpdateScaling) { - data->imgui.m_bWasScalingUpdatedThisFrame = true; + if (data->m_ImGuiData.m_bNeedToUpdateScaling) { + data->m_ImGuiData.m_bWasScalingUpdatedThisFrame = true; } }; @@ -1151,11 +1152,42 @@ static RTN_TYPE RUNTIME_API ImGuiGetScalingSize(RUNTIME_CONTEXT ctx) { return RTN_CONTINUE; } +static RTN_TYPE RUNTIME_API ImGuiLoadFont(RUNTIME_CONTEXT ctx) { + char buf[RUNTIME_STR_LEN]; + int font = wGetIntParam(ctx); + float sz = wGetFloatParam(ctx); + size_t start = wGetIntParam(ctx); + size_t end = wGetIntParam(ctx); + wGetStringParam(ctx, buf, RUNTIME_STR_LEN); + + + ScriptExData* data = ScriptExData::Get(); + return RTN_CONTINUE; +} + +static RTN_TYPE RUNTIME_API ImGuiPushFont(RUNTIME_CONTEXT ctx) { + int font = wGetIntParam(ctx); + ScriptExData* data = ScriptExData::Get(); + data->m_ImGuiData += [=]() { + ImGui::PushFont(reinterpret_cast(font)); + }; + return RTN_CONTINUE; +} + +static RTN_TYPE RUNTIME_API ImGuiPopFont(RUNTIME_CONTEXT ctx) { + int count = wGetIntParam(ctx); + ScriptExData* data = ScriptExData::Get(); + data->m_ImGuiData += [=]() { + ImGui::PopFont(); + }; + return RTN_CONTINUE; +} + static RTN_TYPE RUNTIME_API ImGuiPushStyleVar(RUNTIME_CONTEXT ctx) { int idx = wGetIntParam(ctx); float val = wGetFloatParam(ctx); ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { ImGui::PushStyleVar(idx, val); }; return RTN_CONTINUE; @@ -1166,7 +1198,7 @@ static RTN_TYPE RUNTIME_API ImGuiPushStyleVar2(RUNTIME_CONTEXT ctx) { float x = wGetFloatParam(ctx); float y = wGetFloatParam(ctx); ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { ImGui::PushStyleVar(idx, ImVec2(x, y)); }; return RTN_CONTINUE; @@ -1175,7 +1207,7 @@ static RTN_TYPE RUNTIME_API ImGuiPushStyleVar2(RUNTIME_CONTEXT ctx) { static RTN_TYPE RUNTIME_API ImGuiPopStyleVar(RUNTIME_CONTEXT ctx) { int count = wGetIntParam(ctx); ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { ImGui::PopStyleVar(count); }; return RTN_CONTINUE; @@ -1189,7 +1221,7 @@ static RTN_TYPE RUNTIME_API ImGuiPushStyleColor(RUNTIME_CONTEXT ctx) { int a = wGetIntParam(ctx); ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { ImGui::PushStyleColor(idx, IM_COL32(r, g, b, a)); }; return RTN_CONTINUE; @@ -1198,7 +1230,7 @@ static RTN_TYPE RUNTIME_API ImGuiPushStyleColor(RUNTIME_CONTEXT ctx) { static RTN_TYPE RUNTIME_API ImGuiPopStyleColor(RUNTIME_CONTEXT ctx) { int count = wGetIntParam(ctx); ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { ImGui::PopStyleColor(count); }; return RTN_CONTINUE; @@ -1206,7 +1238,7 @@ static RTN_TYPE RUNTIME_API ImGuiPopStyleColor(RUNTIME_CONTEXT ctx) { static RTN_TYPE RUNTIME_API ImGuiGetWindowDrawList(RUNTIME_CONTEXT ctx) { ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { ImDrawList *drawList = ImGui::GetWindowDrawList(); data->SetData("__WindowDrawlist__", 0, reinterpret_cast(drawList)); }; @@ -1217,7 +1249,7 @@ static RTN_TYPE RUNTIME_API ImGuiGetWindowDrawList(RUNTIME_CONTEXT ctx) { static RTN_TYPE RUNTIME_API ImGuiGetBackgroundDrawList(RUNTIME_CONTEXT ctx) { ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { ImDrawList *drawList = ImGui::GetBackgroundDrawList(); data->SetData("__BackgroundDrawlist__", 0, reinterpret_cast(drawList)); }; @@ -1228,7 +1260,7 @@ static RTN_TYPE RUNTIME_API ImGuiGetBackgroundDrawList(RUNTIME_CONTEXT ctx) { static RTN_TYPE RUNTIME_API ImGuiGetForegroundDrawList(RUNTIME_CONTEXT ctx) { ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { ImDrawList *drawList = ImGui::GetForegroundDrawList(); data->SetData("__ForegroundDrawlist__", 0, reinterpret_cast(drawList)); }; @@ -1253,7 +1285,7 @@ static RTN_TYPE RUNTIME_API ImGuiDrawListAddText(RUNTIME_CONTEXT ctx) { wGetStringWithFrame(ctx, text, RUNTIME_STR_LEN); ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { if (pDrawList) { pDrawList->AddText(pos, IM_COL32(col.x, col.y, col.z, col.w), text); } @@ -1279,7 +1311,7 @@ static RTN_TYPE RUNTIME_API ImGuiDrawListAddLine(RUNTIME_CONTEXT ctx) { float thickness = wGetFloatParam(ctx); ScriptExData* data = ScriptExData::Get(); - data->imgui += [=]() { + data->m_ImGuiData += [=]() { if (pDrawList) { pDrawList->AddLine(p1, p2, IM_COL32(col.x, col.y, col.z, col.w), thickness); } @@ -1309,7 +1341,7 @@ static RTN_TYPE RUNTIME_API ImGuiTabs(RUNTIME_CONTEXT ctx) { } } - data->imgui += [=]() { + data->m_ImGuiData += [=]() { if (ImGui::BeginTabBar(buf)) { for (int i = 0; i < static_cast(items.size()); ++i) { if (ImGui::BeginTabItem(items[i].c_str())) { diff --git a/src/scriptextender.hpp b/src/scriptextender.hpp index 966f5ea..73c6cf1 100644 --- a/src/scriptextender.hpp +++ b/src/scriptextender.hpp @@ -3,270 +3,117 @@ #include #include "table.hpp" #include "hook.h" -#include #include -#include #include #include "opcodemgr.h" -#include "notifypopup.h" #include "imgui_internal.h" +#include "imguiframe.hpp" +#include "notifypopup.h" -extern enum class eGameVer; -extern eGameVer gGameVer; -extern ImGuiContext* GImGui; +/* +* Handles data exchange between ImGui & CLEO +* Repalce with new data when previous is passed +*/ +struct ImGui2ScriptCom { + bool m_bPassed; + std::any m_Val; +}; -class ScriptExData -{ +class ScriptExData { private: - ScriptExData(std::string id): ID(id){} - - /* - * We're storing all the func ptrs that we need for a single frame - * After drawing frame, we clear up the stored ptrs and repeat - */ - struct ImGuiFrame - { - public: - /* - * Overlay colors for imgui images - * Used by ButtonImage(..) - */ - struct ImgOverlay - { - ImVec4 m_fTintCol = ImVec4(1, 1, 1, 1); - ImVec4 m_fBgCol = ImVec4(1, 1, 1, 1); - } m_ImGCol; - - bool m_bRender; // is backBuffer ready for render - ImVec2 m_vecScaling = ImVec2(1, 1); - bool m_bWasScalingUpdatedThisFrame; // was scaling updated - bool m_bNeedToUpdateScaling; // does imgui scaling needs updating for this script - long long lastScriptCall; // last time script called ImGui::Begin(), hide if no script call - - std::vector> buf; // finished buffer for render - std::vector> backBuf; // back buffer being processed - - ImGuiFrame& operator+=(std::function f) - { - // don't push more if back buffer is full - if (!m_bRender) - { - backBuf.push_back(f); - } - return *this; - } - - void DrawFrames() - { - for (auto func : buf) - { - func(); - } - - // if back buffer is render ready switch the buffer and reset render state - if (m_bRender) - { - buf = std::move(backBuf); - m_bRender = false; - } - - time_t curTime = time(NULL); - - // We're clearing our buffer if script isn't responding anymore - bool scriptsPaused = false; - switch(static_cast(gGameVer)) { - case 0: // III - scriptsPaused = *(bool*)0x95CD7C; - break; - case 1: // VC - scriptsPaused = *(bool*)0xA10B36; - break; - case 2: // SA - scriptsPaused = *(bool*)0xB7CB49; - break; - default: - break; - } - - if (curTime-lastScriptCall > 2 || scriptsPaused) { - ClearFrames(); - } + static inline Table> m_FrameCache; + static inline std::vector m_pScriptTable; + static inline bool m_bShowCursorFlag; + static inline std::string m_CurrentScriptID; + static inline size_t m_nFramerate; - if (m_bWasScalingUpdatedThisFrame) { - m_bNeedToUpdateScaling = false; - m_bWasScalingUpdatedThisFrame = false; - } - } + std::string m_ScriptID; - void ClearFrames() - { - buf.clear(); - } - }; - /* - * Handles the return data between imgui frame & script - */ - struct ComData - { - bool m_bPassed; // Was the data passed to the script, if yes, replace with new data - std::any m_Val; - }; + ScriptExData(std::string id): m_ScriptID(id) {} - std::string ID; // script indentifier - /* - * Cached return data of previous frame - * Due to some limitations we can't run the ImGui realtime with the script - * We run the ImGui frames independent of the script and cache the returns to return back to script - */ - static inline Table> frameData; - static inline std::vector scripts; // ptr to all the scripts using ImGui - static inline bool showCursor; // global cursor state flag - static inline std::string curScriptID; // current script identifier - static inline size_t m_nFramerate; public: + ImGuiFrame m_ImGuiData; - ImGuiFrame imgui; - - static size_t GetGameFPS() - { + static size_t GetGameFPS() { return m_nFramerate; } - static void SetCurrentScript(std::string id) - { - curScriptID = id; + static void SetCurrentScript(std::string id) { + m_CurrentScriptID = id; } - static std::string GetCurrentScript() - { - return curScriptID; + static std::string GetCurrentScript() { + return m_CurrentScriptID; } - static ScriptExData* Get() - { - // create the object if it doesn't exist - for (auto it = scripts.begin(); it != scripts.end(); ++it) - { - // return the exisitng data - if ((*it)->ID == curScriptID) - { + static ScriptExData* Get() { + for (auto it = m_pScriptTable.begin(); it != m_pScriptTable.end(); ++it) { + if ((*it)->m_ScriptID == m_CurrentScriptID) { return *it; } } - // return the new data - ScriptExData* script = new ScriptExData(curScriptID); - scripts.push_back(script); + ScriptExData* script = new ScriptExData(m_CurrentScriptID); + m_pScriptTable.push_back(script); return script; } template - T GetData(const char* label, int index, T defaultVal) - { - try - { - ComData *pData = &frameData[label].at(index); + T GetData(const char* label, int index, T defaultVal) { + try { + ImGui2ScriptCom *pData = &m_FrameCache[label].at(index); T val = std::any_cast(pData->m_Val); pData->m_bPassed = true; return val; - } - catch(...) - { + } catch(...) { return defaultVal; } } + template - void SetData(const char* label,size_t index, T val) - { - /* - * Probably a shitty way to do this and gonna fk me later - * But it works so.. - * - * We're only gonna set data if previous one was extracted! - * This fixes an issue with race condition - */ - if (frameData[label].size() < index+1) - { - frameData[label].push_back({false, val}); - } - else - { - if (frameData[label].at(index).m_bPassed) - { - frameData[label].at(index) = {false, val}; + void SetData(const char* label,size_t index, T val) { + // Set data when previous one is retrived + if (m_FrameCache[label].size() < index+1) { + m_FrameCache[label].push_back({false, val}); + } else { + if (m_FrameCache[label].at(index).m_bPassed) { + m_FrameCache[label].at(index) = {false, val}; } } } - static void SetCursorVisible(bool flag) - { - showCursor = flag; + static void SetCursorVisible(bool flag) { + m_bShowCursorFlag = flag; } - static void DrawFrames() - { - // reset stuff - showCursor = false; + static void InitRenderStates() { + for (auto it = m_pScriptTable.begin(); it != m_pScriptTable.end(); ++it) { + (*it)->m_ImGuiData.BeforeRender(); + } + } - // draw frames - for (auto it = scripts.begin(); it != scripts.end(); ++it) - { - (*it)->imgui.DrawFrames(); + static void RenderFrames() { + m_bShowCursorFlag = false; + + for (auto it = m_pScriptTable.begin(); it != m_pScriptTable.end(); ++it) { + (*it)->m_ImGuiData.OnRender(); } NotifiyPopup::Draw(); - // update stuff - Hook::SetMouseState(showCursor); + + Hook::SetMouseState(m_bShowCursorFlag); m_nFramerate = (size_t)ImGui::GetIO().Framerate; } static void SetScaling(ImVec2 scaling) { - for (auto it = scripts.begin(); it != scripts.end(); ++it) - { - (*it)->imgui.m_vecScaling = scaling; - (*it)->imgui.m_bNeedToUpdateScaling = true; + for (auto it = m_pScriptTable.begin(); it != m_pScriptTable.end(); ++it) { + (*it)->m_ImGuiData.m_vecScaling = scaling; + (*it)->m_ImGuiData.m_bNeedToUpdateScaling = true; } } - // Clears all the internal stuff static void Clear() { - scripts.clear(); - frameData.Clear(); - - // Clear ImGui internal states here - auto e = ImGui::GetCurrentContext(); - if (Hook::m_bInitialized && e) { - e->Windows.clear_delete(); - e->WindowsFocusOrder.clear(); - e->WindowsTempSortBuffer.clear(); - e->CurrentWindow = NULL; - e->CurrentWindowStack.clear(); - e->WindowsById.Clear(); - e->NavWindow = NULL; - e->HoveredWindow = e->HoveredWindowUnderMovingWindow = NULL; - e->ActiveIdWindow = e->ActiveIdPreviousFrameWindow = NULL; - e->MovingWindow = NULL; - e->ColorStack.clear(); - e->StyleVarStack.clear(); - e->OpenPopupStack.clear(); - e->BeginPopupStack.clear(); - - e->TabBars.Clear(); - e->CurrentTabBarStack.clear(); - e->ShrinkWidthBuffer.clear(); - - e->ClipperTempData.clear_destruct(); - - e->Tables.Clear(); - e->TablesTempData.clear_destruct(); - e->DrawChannelsTempMergeBuffer.clear(); - - e->ClipboardHandlerData.clear(); - e->MenusIdSubmittedThisFrame.clear(); - e->InputTextState.ClearFreeMemory(); - - e->SettingsWindows.clear(); - e->SettingsHandlers.clear(); - } + m_pScriptTable.clear(); + m_FrameCache.Clear(); } }; \ No newline at end of file