This repository has been archived by the owner on Aug 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
941 additions
and
479 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,129 +1,155 @@ | ||
#define WIN32_LEAN_AND_MEAN | ||
#include <windows.h> | ||
#include <cocos2d.h> | ||
#include "imgui-hook.hpp" | ||
#include "../../src/data.h" | ||
|
||
using namespace cocos2d; | ||
|
||
void ApplyColor() { | ||
auto* colors = ImGui::GetStyle().Colors; | ||
colors[ImGuiCol_Text] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); | ||
colors[ImGuiCol_TextDisabled] = ImVec4(0.50f, 0.50f, 0.50f, 1.00f); | ||
colors[ImGuiCol_WindowBg] = ImVec4(0.15f, 0.15f, 0.22f, 1.00f); | ||
colors[ImGuiCol_ChildBg] = ImVec4(0.15f, 0.15f, 0.22f, 1.00f); | ||
colors[ImGuiCol_PopupBg] = ImVec4(0.15f, 0.15f, 0.22f, 1.00f); | ||
colors[ImGuiCol_Border] = ImVec4(0.43f, 0.43f, 0.50f, 0.50f); | ||
colors[ImGuiCol_BorderShadow] = ImVec4(0.43f, 0.43f, 0.50f, 0.50f); | ||
colors[ImGuiCol_FrameBg] = ImVec4(0.31f, 0.29f, 0.39f, 0.54f); | ||
colors[ImGuiCol_FrameBgHovered] = ImVec4(0.36f, 0.35f, 0.47f, 0.54f); | ||
colors[ImGuiCol_FrameBgActive] = ImVec4(0.45f, 0.43f, 0.56f, 0.54f); | ||
colors[ImGuiCol_TitleBg] = ImVec4(0.22f, 0.21f, 0.30f, 1.00f); | ||
colors[ImGuiCol_TitleBgActive] = ImVec4(0.22f, 0.21f, 0.30f, 1.00f); | ||
colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.22f, 0.21f, 0.30f, 1.00f); | ||
colors[ImGuiCol_MenuBarBg] = ImVec4(0.22f, 0.21f, 0.30f, 1.00f); | ||
colors[ImGuiCol_ScrollbarBg] = ImVec4(0.20f, 0.20f, 0.27f, 1.00f); | ||
colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.31f, 0.29f, 0.39f, 0.54f); | ||
colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.39f, 0.37f, 0.49f, 0.54f); | ||
colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.46f, 0.44f, 0.58f, 0.54f); | ||
colors[ImGuiCol_CheckMark] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); | ||
colors[ImGuiCol_SliderGrab] = ImVec4(1.00f, 1.00f, 1.00f, 0.50f); | ||
colors[ImGuiCol_SliderGrabActive] = ImVec4(1.00f, 1.00f, 1.00f, 0.50f); | ||
colors[ImGuiCol_Button] = ImVec4(0.31f, 0.29f, 0.39f, 0.54f); | ||
colors[ImGuiCol_ButtonHovered] = ImVec4(0.36f, 0.35f, 0.47f, 0.54f); | ||
colors[ImGuiCol_ButtonActive] = ImVec4(0.45f, 0.43f, 0.56f, 0.54f); | ||
colors[ImGuiCol_Header] = ImVec4(0.31f, 0.29f, 0.39f, 0.54f); | ||
colors[ImGuiCol_HeaderHovered] = ImVec4(0.36f, 0.35f, 0.47f, 0.54f); | ||
colors[ImGuiCol_HeaderActive] = ImVec4(0.45f, 0.43f, 0.56f, 0.54f); | ||
colors[ImGuiCol_Separator] = ImVec4(0.43f, 0.43f, 0.50f, 0.50f); | ||
colors[ImGuiCol_SeparatorHovered] = ImVec4(0.43f, 0.43f, 0.50f, 0.50f); | ||
colors[ImGuiCol_SeparatorActive] = ImVec4(0.43f, 0.43f, 0.50f, 0.50f); | ||
colors[ImGuiCol_ResizeGrip] = ImVec4(0.31f, 0.29f, 0.39f, 0.54f); | ||
colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.36f, 0.35f, 0.47f, 0.54f); | ||
colors[ImGuiCol_ResizeGripActive] = ImVec4(0.43f, 0.43f, 0.50f, 0.50f); | ||
colors[ImGuiCol_Tab] = ImVec4(0.31f, 0.29f, 0.39f, 0.54f); | ||
colors[ImGuiCol_TabHovered] = ImVec4(0.36f, 0.35f, 0.47f, 0.54f); | ||
colors[ImGuiCol_TabActive] = ImVec4(0.22f, 0.21f, 0.30f, 1.00f); | ||
colors[ImGuiCol_TabUnfocused] = ImVec4(0.17f, 0.16f, 0.23f, 1.00f); | ||
colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.22f, 0.21f, 0.30f, 1.00f); | ||
colors[ImGuiCol_PlotLines] = ImVec4(0.61f, 0.61f, 0.61f, 1.00f); | ||
colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.00f, 0.43f, 0.35f, 1.00f); | ||
colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f); | ||
colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f); | ||
colors[ImGuiCol_TableHeaderBg] = ImVec4(0.19f, 0.19f, 0.20f, 1.00f); | ||
colors[ImGuiCol_TableBorderStrong] = ImVec4(0.31f, 0.31f, 0.35f, 1.00f); | ||
colors[ImGuiCol_TableBorderLight] = ImVec4(0.23f, 0.23f, 0.25f, 1.00f); | ||
colors[ImGuiCol_TableRowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); | ||
colors[ImGuiCol_TableRowBgAlt] = ImVec4(1.00f, 1.00f, 1.00f, 0.06f); | ||
colors[ImGuiCol_TextSelectedBg] = ImVec4(0.26f, 0.59f, 0.98f, 0.35f); | ||
colors[ImGuiCol_DragDropTarget] = ImVec4(1.00f, 1.00f, 0.00f, 0.90f); | ||
colors[ImGuiCol_NavHighlight] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f); | ||
colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.00f, 1.00f, 1.00f, 0.70f); | ||
colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.20f); | ||
colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.35f); | ||
} | ||
|
||
void ApplyStyle() { | ||
ImGuiStyle& style = ImGui::GetStyle(); | ||
style.WindowBorderSize = 0; | ||
} | ||
#include "imgui_theme.hpp" | ||
#include "font.hpp" | ||
#include <functional> | ||
#include <chrono> | ||
|
||
WNDPROC originalWndProc; | ||
bool isInitialized = false; | ||
bool ImGuiHook::blockMetaInput = true; | ||
std::function<void()> drawFunction = []() {}; | ||
std::function<void()> toggleFunction = []() {}; | ||
HWND hWnd; | ||
|
||
void _stub() {} | ||
std::function<void()> g_drawFunc = _stub; | ||
std::function<void()> ImGuiHook::g_toggleCallback = _stub; | ||
extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); | ||
LRESULT CALLBACK HookedWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); | ||
|
||
void ImGuiHook::setRenderFunction(std::function<void()> func) { | ||
g_drawFunc = func; | ||
} | ||
std::chrono::steady_clock::time_point animationStartTime; | ||
bool isAnimating = false; | ||
bool isFadingIn = false; | ||
|
||
void ImGuiHook::setToggleCallback(std::function<void()> func) { | ||
g_toggleCallback = func; | ||
} | ||
void animateAlpha() | ||
{ | ||
ImGuiStyle& style = ImGui::GetStyle(); | ||
|
||
auto currentTime = std::chrono::steady_clock::now(); | ||
std::chrono::duration<float> diff = currentTime - animationStartTime; | ||
float elapsed = diff.count(); | ||
|
||
bool g_inited = false; | ||
if (elapsed >= 0.10f) | ||
{ | ||
style.Alpha = isFadingIn ? 1.0f : 0.0f; | ||
isAnimating = false; | ||
|
||
void (__thiscall* CCEGLView_swapBuffers)(CCEGLView*); | ||
void __fastcall CCEGLView_swapBuffers_H(CCEGLView* self) { | ||
auto window = self->getWindow(); | ||
if (!isFadingIn) | ||
{ | ||
toggleFunction(); | ||
} | ||
|
||
if (!g_inited) { | ||
g_inited = true; | ||
return; | ||
} | ||
|
||
float t = elapsed / 0.10f; | ||
float alpha = isFadingIn ? 0.0f + t * (1.0f - 0.0f) : 1.0f - t * (1.0f - 0.0f); | ||
style.Alpha = alpha; | ||
} | ||
|
||
void(__thiscall* CCEGLView_swapBuffers)(CCEGLView*); | ||
void __fastcall CCEGLView_swapBuffers_H(CCEGLView* self) | ||
{ | ||
if (!isInitialized) | ||
{ | ||
isInitialized = true; | ||
IMGUI_CHECKVERSION(); | ||
ImGui::CreateContext(); | ||
ImGuiIO& io = ImGui::GetIO(); | ||
io.Fonts->AddFontFromMemoryTTF(fontData, sizeof(fontData), 14.f); | ||
io.IniFilename = NULL; | ||
io.IniFilename = nullptr; | ||
ApplyColor(); | ||
ApplyStyle(); | ||
auto hwnd = WindowFromDC(*reinterpret_cast<HDC*>(reinterpret_cast<uintptr_t>(window) + 0x244)); | ||
ImGui_ImplWin32_Init(hwnd); | ||
hWnd = WindowFromDC(*reinterpret_cast<HDC*>(reinterpret_cast<uintptr_t>(self->getWindow()) + 0x244)); | ||
originalWndProc = (WNDPROC)GetWindowLongPtr(hWnd, GWLP_WNDPROC); | ||
SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)HookedWndProc); | ||
ImGui_ImplWin32_Init(hWnd); | ||
ImGui_ImplOpenGL3_Init(); | ||
} | ||
|
||
ImGui_ImplOpenGL3_NewFrame(); | ||
ImGui_ImplWin32_NewFrame(); | ||
ImGui::NewFrame(); | ||
|
||
g_drawFunc(); | ||
if (isAnimating) | ||
{ | ||
animateAlpha(); | ||
} | ||
|
||
drawFunction(); | ||
|
||
ImGui::EndFrame(); | ||
ImGui::Render(); | ||
|
||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); | ||
|
||
glFlush(); | ||
|
||
CCEGLView_swapBuffers(self); | ||
} | ||
|
||
LRESULT CALLBACK HookedWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) | ||
{ | ||
ImGui_ImplWin32_WndProcHandler(hWnd, msg, wParam, lParam); | ||
|
||
if (msg == WM_KEYDOWN && wParam == 'K' && !ImGui::GetIO().WantCaptureKeyboard) | ||
{ | ||
if (!isAnimating) | ||
{ | ||
isAnimating = true; | ||
isFadingIn = !isFadingIn; | ||
animationStartTime = std::chrono::steady_clock::now(); | ||
|
||
if (isFadingIn) | ||
{ | ||
toggleFunction(); | ||
} | ||
} | ||
} | ||
|
||
if (ImGui::GetIO().WantCaptureMouse && ImGuiHook::blockMetaInput) | ||
{ | ||
if (msg == WM_MOUSEMOVE || msg == WM_LBUTTONDOWN || msg == WM_LBUTTONUP || msg == WM_MOUSEWHEEL) | ||
return 0; | ||
} | ||
|
||
if (ImGui::GetIO().WantCaptureKeyboard) | ||
{ | ||
if (msg == WM_KEYDOWN || msg == WM_KEYUP || msg == WM_SYSKEYDOWN || msg == WM_SYSKEYUP || | ||
msg == WM_HOTKEY || msg == WM_KILLFOCUS || msg == WM_SETFOCUS) | ||
return 0; | ||
} | ||
|
||
return CallWindowProc(originalWndProc, hWnd, msg, wParam, lParam); | ||
} | ||
|
||
void(__thiscall* CCEGLView_toggleFullScreen)(void*, bool); | ||
void __fastcall CCEGLView_toggleFullScreen_H(void* self, void*, bool toggle) | ||
{ | ||
ImGuiHook::Unload(); | ||
CCEGLView_toggleFullScreen(self, toggle); | ||
} | ||
|
||
void ImGuiHook::setupHooks(std::function<void(void*, void*, void**)> hookFunc) { | ||
void ImGuiHook::Load(std::function<void(void*, void*, void**)> hookFunc) | ||
{ | ||
auto cocosBase = GetModuleHandleA("libcocos2d.dll"); | ||
hookFunc( | ||
GetProcAddress(cocosBase, "?swapBuffers@CCEGLView@cocos2d@@UAEXXZ"), | ||
CCEGLView_swapBuffers_H, | ||
reinterpret_cast<void**>(&CCEGLView_swapBuffers) | ||
); | ||
} | ||
hookFunc(GetProcAddress(cocosBase, "?swapBuffers@CCEGLView@cocos2d@@UAEXXZ"), CCEGLView_swapBuffers_H, reinterpret_cast<void**>(&CCEGLView_swapBuffers)); | ||
hookFunc(GetProcAddress(cocosBase, "?toggleFullScreen@CCEGLView@cocos2d@@QAEX_N@Z"), CCEGLView_toggleFullScreen_H, reinterpret_cast<void**>(&CCEGLView_toggleFullScreen)); | ||
} | ||
|
||
void ImGuiHook::Unload() | ||
{ | ||
isInitialized = false; | ||
SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)originalWndProc); | ||
ImGui_ImplOpenGL3_Shutdown(); | ||
ImGui_ImplWin32_Shutdown(); | ||
ImGui::DestroyContext(); | ||
} | ||
|
||
|
||
void ImGuiHook::setRenderFunction(std::function<void()> func) | ||
{ | ||
drawFunction = func; | ||
} | ||
|
||
void ImGuiHook::setToggleFunction(std::function<void()> func) | ||
{ | ||
toggleFunction = func; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
#pragma once | ||
#include <imgui.h> | ||
#include <backends/imgui_impl_win32.h> | ||
#include <backends/imgui_impl_opengl3.h> | ||
#include <Windows.h> | ||
#include <cocos2d.h> | ||
#include <gl/GL.h> | ||
#include <functional> | ||
#include "imgui/imgui.h" | ||
#include "imgui/imgui_impl_opengl3.h" | ||
#include "imgui/imgui_impl_win32.h" | ||
|
||
using namespace cocos2d; | ||
|
||
namespace ImGuiHook { | ||
extern bool blockMetaInput; | ||
extern std::function<void()> g_toggleCallback; | ||
|
||
void setupHooks(std::function<void(void*, void*, void**)> hookFunc); | ||
|
||
void Load(std::function<void(void*, void*, void**)> hookFunc); | ||
void Unload(); | ||
void setRenderFunction(std::function<void()> func); | ||
void setToggleCallback(std::function<void()> func); | ||
void setToggleFunction(std::function<void()> func); | ||
} | ||
|
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.