Skip to content

Commit 11604d4

Browse files
committed
Clean up code
1 parent 7823b0e commit 11604d4

File tree

5 files changed

+309
-319
lines changed

5 files changed

+309
-319
lines changed

src/dllmain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ void ImGuiThread(void* param) {
7575
}
7676
}
7777

78-
if (!Hook::Inject(&ScriptExData::DrawFrames)) {
78+
if (!Hook::Inject(&ScriptExData::RenderFrames)) {
7979
MessageBox(HWND_DESKTOP, "Failed to inject dxhook..", "ImGuiRedux", MB_ICONERROR);
8080
}
8181

src/hook.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ void Hook::ProcessFrame(void* ptr) {
140140
ScriptExData::SetScaling({scaleX, scaleY});
141141
}
142142

143+
ScriptExData::InitRenderStates();
144+
143145
ImGui_ImplWin32_NewFrame();
144146
if (gRenderer == eRenderer::Dx9) {
145147
ImGui_ImplDX9_NewFrame();

src/imguiframe.hpp

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
#pragma once
2+
#include "imgui.h"
3+
#include <vector>
4+
#include <functional>
5+
#include <time.h>
6+
7+
extern enum class eGameVer;
8+
extern eGameVer gGameVer;
9+
10+
struct FontInfo {
11+
bool m_bFontLoaded = false;
12+
ImFont *m_pFont = nullptr;
13+
std::string m_Path;
14+
float m_nSize = 14.0f;
15+
size_t m_nStart, m_nEnd;
16+
};
17+
18+
class ImGuiFrame {
19+
public:
20+
ImGuiContext *m_pContext = nullptr;
21+
22+
// Scaling related
23+
ImVec2 m_vecScaling = ImVec2(1, 1);
24+
bool m_bWasScalingUpdatedThisFrame;
25+
bool m_bNeedToUpdateScaling;
26+
long long m_nLastScriptCallMS;
27+
28+
// Render buffers
29+
bool m_bIsBackBufferReady;
30+
std::vector<std::function<void()>> m_RenderBuffer, m_BackBuffer;
31+
32+
// for ImGui::ImageButton()
33+
ImVec4 m_vecImgTint = ImVec4(1, 1, 1, 1);
34+
ImVec4 m_vecImgBgCol = ImVec4(1, 1, 1, 1);
35+
36+
// Fonts
37+
std::vector<std::pair<size_t, size_t>> m_FontGlyphRange;
38+
std::vector<FontInfo> m_FontTable;
39+
40+
ImGuiFrame() {
41+
// m_pContext = ImGui::CreateContext();
42+
}
43+
44+
ImGuiFrame& operator+=(std::function<void()> f) {
45+
if (!m_bIsBackBufferReady) {
46+
m_BackBuffer.push_back(f);
47+
}
48+
return *this;
49+
}
50+
51+
void BeforeRender() {
52+
// bool buildRequired = false;
53+
// for (auto& e: m_FontTable) {
54+
// if (!e.m_bFontLoaded) {
55+
// ImWchar ranges[] = {
56+
// e.m_nStart, e.m_nEnd, 0
57+
// };
58+
// ImGui::GetIO().Fonts->AddFontFromFileTTF(e.m_Path.c_str(), e.m_nSize, NULL, ranges);
59+
// buildRequired = true;
60+
// }
61+
// }
62+
63+
// if (buildRequired) {
64+
// ImGui::GetIO().Fonts->Build();
65+
// }
66+
}
67+
68+
void OnRender() {
69+
for (auto func : m_RenderBuffer) {
70+
func();
71+
}
72+
73+
// if back buffer is render ready switch the buffer and reset render state
74+
if (m_bIsBackBufferReady) {
75+
m_RenderBuffer = std::move(m_BackBuffer);
76+
m_bIsBackBufferReady = false;
77+
}
78+
79+
time_t curTime = time(NULL);
80+
// Clear buffer when script stops responding
81+
bool scriptsPaused = false;
82+
switch(static_cast<int>(gGameVer)) {
83+
case 0: // III
84+
scriptsPaused = *(bool*)0x95CD7C;
85+
break;
86+
case 1: // VC
87+
scriptsPaused = *(bool*)0xA10B36;
88+
break;
89+
case 2: // SA
90+
scriptsPaused = *(bool*)0xB7CB49;
91+
break;
92+
default:
93+
break;
94+
}
95+
96+
if (curTime-m_nLastScriptCallMS > 2 || scriptsPaused) {
97+
OnClear();
98+
}
99+
100+
if (m_bWasScalingUpdatedThisFrame) {
101+
m_bNeedToUpdateScaling = false;
102+
m_bWasScalingUpdatedThisFrame = false;
103+
}
104+
}
105+
106+
void OnClear() {
107+
m_RenderBuffer.clear();
108+
}
109+
};

0 commit comments

Comments
 (0)