Skip to content
This repository has been archived by the owner on Aug 6, 2024. It is now read-only.

Commit

Permalink
Beta 2
Browse files Browse the repository at this point in the history
  • Loading branch information
TobyAdd committed May 23, 2023
1 parent def5586 commit 03216d0
Show file tree
Hide file tree
Showing 28 changed files with 941 additions and 479 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ project(${PROJECT})
file(GLOB_RECURSE SOURCE_FILES src/*.cpp)
add_library(${PROJECT} SHARED ${SOURCE_FILES})

add_compile_definitions(UNICODE _UNICODE)

target_include_directories(${PROJECT} PRIVATE
libs/minhook/include
libs/gd.h/include
Expand All @@ -25,6 +27,7 @@ target_link_libraries(${PROJECT} minhook imgui-hook opengl32 cocos2d)

target_link_libraries(${PROJECT} ${CMAKE_SOURCE_DIR}/libs/cocos-headers/cocos2dx/libcocos2d.lib)
target_link_libraries(${PROJECT} ${CMAKE_SOURCE_DIR}/libs/cocos-headers/extensions/libExtensions.lib)
target_link_libraries(${PROJECT} ${CMAKE_SOURCE_DIR}/libs/glew32.lib)

# add_custom_command(TARGET ${PROJECT} POST_BUILD
# COMMAND ${CMAKE_COMMAND} -E copy
Expand Down
1 change: 1 addition & 0 deletions libs/gd.h/sprite_nodes/GameObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ namespace gd {
kGameObjectTypeWavePortal = 26,
kGameObjectTypeRobotPortal = 27,
kGameObjectTypeTeleportPortal = 28,
kGameObjectTypeGreenRing = 29,
kGameObjectTypeCollectible = 30,
kGameObjectTypeUserCoin = 31,
kGameObjectTypeDropRing = 32,
Expand Down
Binary file added libs/glew32.lib
Binary file not shown.
11 changes: 6 additions & 5 deletions libs/imgui-hook/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
cmake_minimum_required(VERSION 3.0)

add_library(imgui-hook STATIC
imgui-hook.cpp
imgui/imgui.cpp
imgui/imgui_widgets.cpp
imgui/imgui_demo.cpp
imgui/imgui_draw.cpp
imgui/imgui_impl_opengl3.cpp
imgui/imgui_impl_win32.cpp
imgui/imgui_tables.cpp
imgui/imgui_draw.cpp
imgui/backends/imgui_impl_win32.cpp
imgui/backends/imgui_impl_opengl3.cpp
imgui/imgui_widgets.cpp
imgui-hook.cpp
)
set_property(TARGET imgui-hook PROPERTY CXX_STANDARD 17)
target_include_directories(imgui-hook PRIVATE imgui
Expand Down
4 changes: 0 additions & 4 deletions libs/imgui-hook/README.md

This file was deleted.

File renamed without changes.
216 changes: 121 additions & 95 deletions libs/imgui-hook/imgui-hook.cpp
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;
}
21 changes: 12 additions & 9 deletions libs/imgui-hook/imgui-hook.hpp
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);
}

21 changes: 0 additions & 21 deletions libs/imgui-hook/imgui/LICENSE.txt

This file was deleted.

Loading

0 comments on commit 03216d0

Please sign in to comment.