diff --git a/src/micetools/dll/dllmain.c b/src/micetools/dll/dllmain.c index ca7aad1..ef1468c 100644 --- a/src/micetools/dll/dllmain.c +++ b/src/micetools/dll/dllmain.c @@ -150,7 +150,9 @@ void tea_hook_test(char* fmt, ...) { int mxkMain(); DWORD WINAPI MxkThreadProc(LPVOID lpParameter) { mxkMain(); }; -void spawn_pcp_processes(void) { CreateThread(NULL, 0, &MxkThreadProc, NULL, 0, NULL); } +void spawn_pcp_processes(void) { + // CreateThread(NULL, 0, &MxkThreadProc, NULL, 0, NULL); +} BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { if (ul_reason_for_call != DLL_PROCESS_ATTACH) return TRUE; diff --git a/src/micetools/dll/hooks/gui.c b/src/micetools/dll/hooks/gui.c index 6f59657..81ab794 100644 --- a/src/micetools/dll/hooks/gui.c +++ b/src/micetools/dll/hooks/gui.c @@ -372,13 +372,16 @@ void hook_gui() { hook("User32.dll", "ChangeDisplaySettingsExW", FakeChangeDisplaySettingsExW, (void**)&TrueChangeDisplaySettingsExW); hook("D3d9.dll", "Direct3DCreate9", FakeDirect3DCreate9, (void**)&TrueDirect3DCreate9); - // Hooked as a way to identify use of GLUT - hook("FREEGLUT.DLL", "glutInitDisplayMode", Fake_glutInitDisplayMode, - (void**)&True_glutInitDisplayMode); - hook("FREEGLUT.DLL", "glutFullScreen", Fake_glutFullScreen, (void**)&True_glutFullScreen); - hook("FREEGLUT.DLL", "glutPositionWindow", Fake_glutPositionWindow, - (void**)&True_glutPositionWindow); - hook("FREEGLUT.DLL", "glutReshapeWindow", Fake_glutReshapeWindow, - (void**)&True_glutReshapeWindow); - hook("FREEGLUT.DLL", "glutSwapBuffers", Fake_glutSwapBuffers, (void**)&True_glutSwapBuffers); + if (PathFileExistsA("FREEGLUT.DLL")) { + // Hooked as a way to identify use of GLUT + hook("FREEGLUT.DLL", "glutInitDisplayMode", Fake_glutInitDisplayMode, + (void**)&True_glutInitDisplayMode); + hook("FREEGLUT.DLL", "glutFullScreen", Fake_glutFullScreen, (void**)&True_glutFullScreen); + hook("FREEGLUT.DLL", "glutPositionWindow", Fake_glutPositionWindow, + (void**)&True_glutPositionWindow); + hook("FREEGLUT.DLL", "glutReshapeWindow", Fake_glutReshapeWindow, + (void**)&True_glutReshapeWindow); + hook("FREEGLUT.DLL", "glutSwapBuffers", Fake_glutSwapBuffers, + (void**)&True_glutSwapBuffers); + } } diff --git a/src/micetools/dll/meson.build b/src/micetools/dll/meson.build index 52af9c2..c2039de 100644 --- a/src/micetools/dll/meson.build +++ b/src/micetools/dll/meson.build @@ -33,5 +33,8 @@ shared_library( include_directories: [ openssl_inc, ], - dependencies: [cimgui.get_variable('cimgui_dep'), freeglut_lib] + dependencies: [ + cimgui.get_variable('cimgui_dep'), + # freeglut_lib, # forces the use of freeglut.dll! + ] ) diff --git a/src/micetools/launcher/main.c b/src/micetools/launcher/main.c index 101ba81..569127b 100644 --- a/src/micetools/launcher/main.c +++ b/src/micetools/launcher/main.c @@ -55,7 +55,6 @@ void parse_cmdline(int argc, char* argv[]) { int main(int argc, char* argv[]) { load_mice_config(); - fprintf(stderr, "Argc: %d\n", argc); CHAR workDir[MAX_PATH + 1]; GetCurrentDirectory(MAX_PATH, workDir); fprintf(stderr, "Work dir: %s\n", workDir); diff --git a/src/micetools/lib/mice/config.c b/src/micetools/lib/mice/config.c index 1c64524..5f67af8 100644 --- a/src/micetools/lib/mice/config.c +++ b/src/micetools/lib/mice/config.c @@ -214,7 +214,6 @@ void load_mice_config() { if (MiceConfig.keys.board_count > JVS_IO_MAX) MiceConfig.keys.board_count = JVS_IO_MAX; char *text = MiceConfig.keys.keys; - printf("Text: %s\n", text); if (text) { char *copy = (char *)malloc(strlen(text) + 1); memcpy_s(copy, strlen(text) + 1, text, strlen(text) + 1); diff --git a/src/micetools/lib/mice/exe.c b/src/micetools/lib/mice/exe.c index 9018197..7f1da50 100644 --- a/src/micetools/lib/mice/exe.c +++ b/src/micetools/lib/mice/exe.c @@ -33,7 +33,7 @@ bool remote_call(HANDLE process, LPVOID function, LPCSTR argument, DWORD* result HANDLE remote_thread = CreateRemoteThread(process, NULL, 0, (LPTHREAD_START_ROUTINE)function, arg_addr, 0, NULL); - if (remote_thread == NULL) { + if (remote_thread == INVALID_HANDLE_VALUE) { fprintf(stderr, "Fatal: CreateRemoteThread failed: %03x\n", GetLastError()); return false; } @@ -99,16 +99,14 @@ HANDLE start_and_inject(LPCSTR path, LPSTR cmdline, LPCSTR inject, BOOL debug_wa // Start the binary flags |= CREATE_SUSPENDED; - if (!CreateProcessA(path, cmdline, NULL, NULL, FALSE, flags, NULL, NULL, - &startupInfo, &processInformation)) { + if (!CreateProcessA(path, cmdline, NULL, NULL, FALSE, flags, NULL, NULL, &startupInfo, + &processInformation)) { fprintf(stderr, "Fatal: CreateProcessA failed: %03x\n", GetLastError()); goto abort; } - if (debug_wait) { + if (debug_wait) if (!inject_debug_wait(processInformation.hProcess)) goto abort; - } - // Sleep(5000); if (!inject_dll(processInformation.hProcess, inject)) goto abort; if (extra_injections != NULL && extra_injections[0] != '\0') { @@ -140,15 +138,15 @@ HANDLE start_and_inject(LPCSTR path, LPSTR cmdline, LPCSTR inject, BOOL debug_wa return processInformation.hProcess; abort: - if (processInformation.hProcess) { - if (!CloseHandle(processInformation.hThread)) + if (processInformation.hProcess && processInformation.hProcess != INVALID_HANDLE_VALUE) { + if (!CloseHandle(processInformation.hThread) && GetLastError() != ERROR_INVALID_HANDLE) fprintf(stderr, "Fatal: CloseHandle(hProcess) failed: %03x\n", GetLastError()); if (!TerminateProcess(processInformation.hProcess, 1)) fprintf(stderr, "Fatal: TerminateProcess failed: %03x\n", GetLastError()); } - if (processInformation.hThread) { - if (!CloseHandle(processInformation.hThread)) + if (processInformation.hThread && processInformation.hThread != INVALID_HANDLE_VALUE) { + if (!CloseHandle(processInformation.hThread) && GetLastError() != ERROR_INVALID_HANDLE) fprintf(stderr, "Fatal: CloseHandle(hThread) failed: %03x\n", GetLastError()); } diff --git a/subprojects/cimgui_dep/imgui/backends/GL/freeglut.cpp b/subprojects/cimgui_dep/imgui/backends/GL/freeglut.cpp new file mode 100644 index 0000000..f9d864d --- /dev/null +++ b/subprojects/cimgui_dep/imgui/backends/GL/freeglut.cpp @@ -0,0 +1,38 @@ +#include "freeglut.h" + +#include + +HMODULE hFreeGLUT = 0; + +#define WRAP(procName, ret) \ + if (!hFreeGLUT) hFreeGLUT = LoadLibraryA("freeglut.dll"); \ + if (hFreeGLUT == INVALID_HANDLE_VALUE) return ret; \ + return ((decltype(procName)*)(GetProcAddress(hFreeGLUT, #procName))) + +void FGAPIENTRY glutPassiveMotionFunc(void (*callback)(int, int)) { + WRAP(glutPassiveMotionFunc, )(callback); +} +void FGAPIENTRY glutKeyboardUpFunc(void (*callback)(unsigned char, int, int)) { + WRAP(glutKeyboardUpFunc, )(callback); +} +void FGAPIENTRY glutMouseFunc(void (*callback)(int, int, int, int)) { + WRAP(glutMouseFunc, )(callback); +} +void FGAPIENTRY glutKeyboardFunc(void (*callback)(unsigned char, int, int)) { + WRAP(glutKeyboardFunc, )(callback); +} +void FGAPIENTRY glutSpecialFunc(void (*callback)(int, int, int)) { + WRAP(glutSpecialFunc, )(callback); +} +void FGAPIENTRY glutMotionFunc(void (*callback)(int, int)) { WRAP(glutMotionFunc, )(callback); } +int FGAPIENTRY glutGet(unsigned int query) { WRAP(glutGet, -1)(query); } +void FGAPIENTRY glutReshapeFunc(void (*callback)(int, int)) { WRAP(glutReshapeFunc, )(callback); } +int FGAPIENTRY glutGetModifiers(void) { WRAP(glutGetModifiers, -1)(); } + +void FGAPIENTRY glutSpecialUpFunc(void (*callback)(int, int, int)) { + WRAP(glutSpecialUpFunc, )(callback); +} + +void FGAPIENTRY glutMouseWheelFunc(void (*callback)(int, int, int, int)) { + WRAP(glutMouseWheelFunc, )(callback); +} diff --git a/subprojects/cimgui_dep/imgui/backends/GL/freeglut_std.h b/subprojects/cimgui_dep/imgui/backends/GL/freeglut_std.h index 55539e5..4939066 100644 --- a/subprojects/cimgui_dep/imgui/backends/GL/freeglut_std.h +++ b/subprojects/cimgui_dep/imgui/backends/GL/freeglut_std.h @@ -78,7 +78,9 @@ /* Link with Win32 shared freeglut lib */ # if FREEGLUT_LIB_PRAGMAS -# pragma comment (lib, "freeglut.lib") +// Disabled! We're going to to load freeglut in at runtime! +// # pragma comment (lib, "freeglut.lib") +# define FGAPI extern # endif # endif diff --git a/subprojects/cimgui_dep/imgui/meson.build b/subprojects/cimgui_dep/imgui/meson.build index 9696ba9..e5262c7 100644 --- a/subprojects/cimgui_dep/imgui/meson.build +++ b/subprojects/cimgui_dep/imgui/meson.build @@ -15,6 +15,7 @@ if get_option('opengl2').enabled() endif if get_option('glut').enabled() sources += 'backends/imgui_impl_glut.cpp' + sources += 'backends/GL/freeglut.cpp' endif if get_option('dx11').enabled() sources += 'backends/imgui_impl_dx11.cpp'