Skip to content

Commit

Permalink
Backup latest changes
Browse files Browse the repository at this point in the history
  • Loading branch information
user-grinch committed May 4, 2022
1 parent 2568c58 commit c922105
Show file tree
Hide file tree
Showing 17 changed files with 1,765 additions and 83 deletions.
2 changes: 1 addition & 1 deletion .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
],
"defines": [
"_DEBUG",
"_DX9_SDK_INSTALLED",
"_DX9_SDK_INSTALLED"
],
"windowsSdkVersion": "10.0.19041.0",
"compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30037/bin/Hostx64/x64/cl.exe",
Expand Down
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
"name": "Launch Game",
"type": "cppvsdbg",
"request": "launch",
"program": "E:/AmongUs/AmongUs.exe",
"program": "E:/AmongUs/Among Us.exe",
"args": [],
"stopAtEntry": false,
"cwd": "E:/AmongUs/",
"cwd": "E:/AmongUs",
"environment": [],
"console": "internalConsole"
},
Expand Down
812 changes: 812 additions & 0 deletions include/imgui/imgui_impl_opengl3.cpp

Large diffs are not rendered by default.

55 changes: 55 additions & 0 deletions include/imgui/imgui_impl_opengl3.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// dear imgui: Renderer Backend for modern OpenGL with shaders / programmatic pipeline
// - Desktop GL: 2.x 3.x 4.x
// - Embedded GL: ES 2.0 (WebGL 1.0), ES 3.0 (WebGL 2.0)
// This needs to be used along with a Platform Backend (e.g. GLFW, SDL, Win32, custom..)

// Implemented features:
// [X] Renderer: User texture binding. Use 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID!
// [x] Renderer: Desktop GL only: Support for large meshes (64k+ vertices) with 16-bit indices.

// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
// If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp.
// Read online: https://github.com/ocornut/imgui/tree/master/docs

// About GLSL version:
// The 'glsl_version' initialization parameter should be NULL (default) or a "#version XXX" string.
// On computer platform the GLSL version default to "#version 130". On OpenGL ES 3 platform it defaults to "#version 300 es"
// Only override if your GL version doesn't handle this GLSL version. See GLSL version table at the top of imgui_impl_opengl3.cpp.

#pragma once
#include "imgui.h" // IMGUI_IMPL_API

// Backend API
IMGUI_IMPL_API bool ImGui_ImplOpenGL3_Init(const char* glsl_version = NULL);
IMGUI_IMPL_API void ImGui_ImplOpenGL3_Shutdown();
IMGUI_IMPL_API void ImGui_ImplOpenGL3_NewFrame();
IMGUI_IMPL_API void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data);

// (Optional) Called by Init/NewFrame/Shutdown
IMGUI_IMPL_API bool ImGui_ImplOpenGL3_CreateFontsTexture();
IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyFontsTexture();
IMGUI_IMPL_API bool ImGui_ImplOpenGL3_CreateDeviceObjects();
IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyDeviceObjects();

// Specific OpenGL ES versions
//#define IMGUI_IMPL_OPENGL_ES2 // Auto-detected on Emscripten
//#define IMGUI_IMPL_OPENGL_ES3 // Auto-detected on iOS/Android

// You can explicitly select GLES2 or GLES3 API by using one of the '#define IMGUI_IMPL_OPENGL_LOADER_XXX' in imconfig.h or compiler command-line.
#if !defined(IMGUI_IMPL_OPENGL_ES2) \
&& !defined(IMGUI_IMPL_OPENGL_ES3)

// Try to detect GLES on matching platforms
#if defined(__APPLE__)
#include <TargetConditionals.h>
#endif
#if (defined(__APPLE__) && (TARGET_OS_IOS || TARGET_OS_TV)) || (defined(__ANDROID__))
#define IMGUI_IMPL_OPENGL_ES3 // iOS, Android -> GL ES 3, "#version 300 es"
#elif defined(__EMSCRIPTEN__) || defined(__amigaos4__)
#define IMGUI_IMPL_OPENGL_ES2 // Emscripten -> GL ES 2, "#version 100"
#else
// Otherwise imgui_impl_opengl3_loader.h will be used.
#endif

#endif
757 changes: 757 additions & 0 deletions include/imgui/imgui_impl_opengl3_loader.h

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion include/kiero/kiero.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#define KIERO_INCLUDE_D3D10 0 // 1 if you need D3D10 hook
#define KIERO_INCLUDE_D3D11 1 // 1 if you need D3D11 hook
#define KIERO_INCLUDE_D3D12 0 // 1 if you need D3D12 hook
#define KIERO_INCLUDE_OPENGL 0 // 1 if you need OpenGL hook
#define KIERO_INCLUDE_OPENGL 1 // 1 if you need OpenGL hook
#define KIERO_INCLUDE_VULKAN 0 // 1 if you need Vulkan hook
#define KIERO_USE_MINHOOK 1 // 1 if you will use kiero::bind function

Expand Down
88 changes: 68 additions & 20 deletions src/d3dhook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
#include "MinHook.h"
#include "imgui_impl_dx9.h"
#include "imgui_impl_dx11.h"
#include "imgui_impl_opengl3.h"
#include "imgui_impl_win32.h"
#include "injector.hpp"

eRenderer gRenderer;
eGameVer gGameVer;

extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);

bool D3dHook::GetMouseState()
Expand Down Expand Up @@ -94,10 +92,14 @@ void D3dHook::ProcessFrame(void* ptr)
{
ImGui_ImplDX9_InvalidateDeviceObjects();
}
else
else if (gRenderer == eRenderer::DX11)
{
ImGui_ImplDX11_InvalidateDeviceObjects();
}
else
{
ImGui_ImplOpenGL3_Shutdown();
}

ImGuiIO& io = ImGui::GetIO();
io.Fonts->Clear();
Expand Down Expand Up @@ -130,10 +132,14 @@ void D3dHook::ProcessFrame(void* ptr)
{
ImGui_ImplDX9_NewFrame();
}
else
else if (gRenderer == eRenderer::DX11)
{
ImGui_ImplDX11_NewFrame();
}
else
{
ImGui_ImplOpenGL3_NewFrame();
}

ImGui::NewFrame();

Expand All @@ -149,10 +155,14 @@ void D3dHook::ProcessFrame(void* ptr)
{
ImGui_ImplDX9_RenderDrawData(ImGui::GetDrawData());
}
else
else if (gRenderer == eRenderer::DX11)
{
ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData());
}
else
{
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
}
}
else
{
Expand All @@ -168,7 +178,7 @@ void D3dHook::ProcessFrame(void* ptr)
{
ImGui_ImplDX9_Init(reinterpret_cast<IDirect3DDevice9*>(ptr));
}
else
else if (gRenderer == eRenderer::DX11)
{
// for dx11 device ptr is swapchain
reinterpret_cast<IDXGISwapChain*>(ptr)->GetDevice(__uuidof(ID3D11Device), &ptr);
Expand All @@ -177,6 +187,10 @@ void D3dHook::ProcessFrame(void* ptr)

ImGui_ImplDX11_Init(reinterpret_cast<ID3D11Device*>(ptr), context);
}
else
{
ImGui_ImplOpenGL3_Init();
}

ImGui_ImplWin32_EnableDpiAwareness();

Expand All @@ -203,6 +217,12 @@ HRESULT D3dHook::hkPresent(IDXGISwapChain* pSwapChain, UINT SyncInterval, UINT F
return oPresent(pSwapChain, SyncInterval, Flags);
}

BOOL D3dHook::hkGlSwapBuffer(HDC hDc)
{
ProcessFrame(nullptr);
return oGlSwapBuffer(hDc);
}

void D3dHook::ProcessMouse()
{
static bool curState;
Expand Down Expand Up @@ -304,29 +324,44 @@ bool D3dHook::InjectHook(void *pCallback)
{
rhInstalled = true;
}

if (!rhInstalled && init(kiero::RenderType::D3D9) == kiero::Status::Success)

if (rhInstalled)
{
goto render_hook;
}

if (init(kiero::RenderType::D3D9) == kiero::Status::Success)
{
gRenderer = eRenderer::DX9;
hookInjected = true;
kiero::bind(16, (void**)&oReset, hkReset);
kiero::bind(42, (void**)&oEndScene, hkEndScene);
pCallbackFunc = pCallback;
}
else

if (init(kiero::RenderType::OpenGL) == kiero::Status::Success)
{
gRenderer = eRenderer::OPENGL;
hookInjected = true;

if (init(kiero::RenderType::D3D11) == kiero::Status::Success)
HMODULE hMod = GetModuleHandle("OPENGL32.dll");
if (!hMod)
{
gRenderer = eRenderer::DX11;
kiero::bind(8, (void**)&oPresent, hkPresent);
pCallbackFunc = pCallback;
hookInjected = true;
}
else
{
gRenderer = eRenderer::UNKNOWN;
return false;
}
FARPROC addr = GetProcAddress(hMod, "wglSwapBuffers");
MH_CreateHook(addr, hkGlSwapBuffer, (void**)&oGlSwapBuffer);
MH_EnableHook(addr);
pCallbackFunc = pCallback;
}

render_hook:
if (init(kiero::RenderType::D3D11) == kiero::Status::Success)
{
gRenderer = eRenderer::DX11;
kiero::bind(8, (void**)&oPresent, hkPresent);
pCallbackFunc = pCallback;
hookInjected = true;
}

return hookInjected;
Expand All @@ -340,7 +375,20 @@ void D3dHook::RemoveHook()
#else
SetWindowLongPtr(hwnd, GWL_WNDPROC, (LRESULT)oWndProc);
#endif
ImGui_ImplDX9_Shutdown();

if (gRenderer == eRenderer::DX9)
{
ImGui_ImplDX9_Shutdown();
}
if (gRenderer == eRenderer::DX11)
{
ImGui_ImplDX11_Shutdown();
}
else
{
ImGui_ImplOpenGL3_Shutdown();
}

ImGui_ImplWin32_Shutdown();
ImGui::DestroyContext();
kiero::shutdown();
Expand Down
7 changes: 6 additions & 1 deletion src/d3dhook.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#pragma warning(push, 0)
#include <d3d9.h>
#include <d3d11.h>
#include <d3d11Shader.h>
#include <GL/gl.h>
#pragma warning(pop)

class D3dHook
Expand All @@ -11,11 +11,14 @@ class D3dHook
using f_EndScene = HRESULT(CALLBACK*)(IDirect3DDevice9*);
using f_Present = HRESULT(CALLBACK*)(IDXGISwapChain*, UINT, UINT);
using f_Reset = HRESULT(CALLBACK*)(IDirect3DDevice9*, D3DPRESENT_PARAMETERS*);
using f_SwapBuffer = BOOL(CALLBACK*) (HDC hDc);

static inline WNDPROC oWndProc;
static inline f_Present oPresent;
static inline f_EndScene oEndScene;
static inline f_Reset oReset;
static inline f_SwapBuffer oGlSwapBuffer;

static inline bool mouseShown;
static inline void* pCallbackFunc = nullptr;
static inline HWND hwnd = NULL;
Expand All @@ -31,6 +34,8 @@ class D3dHook
// DirectX11, Renderhook
static HRESULT CALLBACK hkPresent(IDXGISwapChain* pSwapChain, UINT SyncInterval, UINT Flags);

// OpenGL
static BOOL CALLBACK hkGlSwapBuffer(HDC hDc);
public:

D3dHook() = delete;
Expand Down
Loading

0 comments on commit c922105

Please sign in to comment.