Skip to content

Commit

Permalink
Fix OnCKPlay and OnCKReset
Browse files Browse the repository at this point in the history
  • Loading branch information
doyaGu committed Jul 27, 2024
1 parent 78c434e commit 8d8b728
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 26 deletions.
38 changes: 17 additions & 21 deletions src/ModManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,36 +70,33 @@ CKERROR ModManager::OnCKEnd() {
}

CKERROR ModManager::OnCKPlay() {
if (m_Context->IsReseted() && m_Context->GetCurrentLevel() != nullptr) {
if (!m_RenderContext) {
m_RenderContext = m_Context->GetPlayerRenderContext();
m_Logger->Info("Get Render Context pointer 0x%08x", m_RenderContext);
if (m_Context->IsReseted() && m_Context->GetCurrentLevel() != nullptr && !m_RenderContext) {
m_RenderContext = m_Context->GetPlayerRenderContext();
m_Logger->Info("Get Render Context pointer 0x%08x", m_RenderContext);

Overlay::ImGuiInitRenderer(m_Context);
}
Overlay::ImGuiInitRenderer(m_Context);
Overlay::ImGuiContextScope scope;

if (!AreModsDown()) {
Overlay::ImGuiContextScope scope;
LoadMods();
InitMods();

LoadMods();
InitMods();
}
Overlay::ImGuiNewFrame();
}

return CK_OK;
}

CKERROR ModManager::OnCKReset() {
if (m_Context->GetCurrentLevel() != nullptr) {
if (!AreModsDown()) {
ShutdownMods();
UnloadMods();
}
if (m_Context->GetCurrentLevel() != nullptr && m_RenderContext) {
Overlay::ImGuiContextScope scope;
Overlay::ImGuiEndFrame();

if (m_RenderContext) {
Overlay::ImGuiShutdownRenderer(m_Context);
m_RenderContext = nullptr;
}
ShutdownMods();
UnloadMods();

Overlay::ImGuiShutdownRenderer(m_Context);

m_RenderContext = nullptr;
}

return CK_OK;
Expand Down Expand Up @@ -350,7 +347,6 @@ void ModManager::ShutdownMods() {
m_CommandMap.clear();

m_ModsInited = false;
m_ModsDown = true;
}

int ModManager::GetModCount() {
Expand Down
2 changes: 0 additions & 2 deletions src/ModManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ class ModManager : public CKBaseManager, public IBML {
bool IsInitialized() const { return m_Initialized; }
bool AreModsLoaded() const { return m_ModsLoaded; }
bool AreModsInited() const { return m_ModsInited; }
bool AreModsDown() const { return m_ModsDown; }

bool Init();
bool Shutdown();
Expand Down Expand Up @@ -321,7 +320,6 @@ class ModManager : public CKBaseManager, public IBML {
bool m_Initialized = false;
bool m_ModsLoaded = false;
bool m_ModsInited = false;
bool m_ModsDown = false;

bool m_Ingame = false;
bool m_InLevel = false;
Expand Down
20 changes: 17 additions & 3 deletions src/Overlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace Overlay {
ImGuiContext *g_ImGuiContext = nullptr;
bool g_ImGuiReady = false;
bool g_RenderReady = false;
bool g_NewFrame = false;

LRESULT OnWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
ImGuiContextScope scope;
Expand Down Expand Up @@ -142,6 +143,9 @@ namespace Overlay {
ImGuiContextScope scope;

ImGui_ImplWin32_Shutdown();

g_RenderReady = false;
g_ImGuiReady = false;
}

void ImGuiShutdownRenderer(CKContext *context) {
Expand All @@ -154,18 +158,28 @@ namespace Overlay {
}

void ImGuiNewFrame() {
if (g_ImGuiReady) {
if (g_ImGuiReady && !g_NewFrame) {
g_RenderReady = false;

ImGui_ImplWin32_NewFrame();
ImGui_ImplCK2_NewFrame();
ImGui::NewFrame();

g_NewFrame = true;
}
}

void ImGuiEndFrame() {
if (g_NewFrame) {
ImGui::EndFrame();
g_NewFrame = false;
}
}

void ImGuiRender() {
if (g_ImGuiReady) {
if (g_NewFrame) {
ImGui::Render();
g_NewFrame = false;
g_RenderReady = true;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/Overlay.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ namespace Overlay {
void ImGuiShutdownRenderer(CKContext *context);

void ImGuiNewFrame();
void ImGuiEndFrame();
void ImGuiRender();
void ImGuiOnRender();
};
Expand Down

0 comments on commit 8d8b728

Please sign in to comment.