1
0
mirror of synced 2024-11-14 09:47:42 +01:00
bananatools/saohook/dllmain.c

126 lines
2.6 KiB
C
Raw Normal View History

2023-09-18 10:05:22 +02:00
#include <windows.h>
#include <stdlib.h>
#include "saohook/config.h"
#include "saohook/sao-dll.h"
#include "saohook/usio.h"
#include "saohook/unity.h"
2023-12-11 00:48:47 +01:00
#include "saohook/systype.h"
#include "saohook/touch.h"
2023-09-18 10:05:22 +02:00
#include "amcus/amcus.h"
#include "hook/process.h"
#include "hooklib/serial.h"
#include "board/sg-reader.h"
#include "board/vfd.h"
#include "platform/platform.h"
#include "gfxhook/gfx.h"
#include "gfxhook/dxgi.h"
#include "gfxhook/d3d11.h"
#include "util/dprintf.h"
static HMODULE sao_hook_mod;
static process_entry_t sao_startup;
static struct sao_hook_config sao_hook_cfg;
static DWORD CALLBACK sao_pre_startup(void)
{
HRESULT hr;
dprintf("--- Begin sao_pre_startup ---\n");
sao_hook_config_load(&sao_hook_cfg, L".\\bananatools.ini");
serial_hook_init();
struct dongle_info dinfo;
dinfo.pid = 0x0C00;
dinfo.vid = 0x0B9A;
hr = platform_hook_init(&sao_hook_cfg.platform, PLATFORM_BNA1, NULL, sao_hook_mod, dinfo);
if (FAILED(hr)) {
ExitProcess(EXIT_FAILURE);
}
2024-10-06 20:37:20 +02:00
hr = sg_reader_hook_init(&sao_hook_cfg.aime, 1, 3, sao_hook_mod);
2023-09-18 10:05:22 +02:00
if (FAILED(hr)) {
ExitProcess(EXIT_FAILURE);
}
2024-10-06 20:37:20 +02:00
hr = vfd_hook_init(&sao_hook_cfg.vfd, 2);
2023-09-18 10:05:22 +02:00
if (FAILED(hr)) {
ExitProcess(EXIT_FAILURE);
}
hr = sao_dll_init(&sao_hook_cfg.dll, sao_hook_mod);
if (FAILED(hr)) {
ExitProcess(EXIT_FAILURE);
}
hr = sao_usio_hook_init(&sao_hook_cfg.usio);
if (FAILED(hr)) {
ExitProcess(EXIT_FAILURE);
}
hr = amcus_hook_init(&sao_hook_cfg.amcus);
if (FAILED(hr)) {
ExitProcess(EXIT_FAILURE);
}
2023-12-11 00:48:47 +01:00
hr = systype_hook_init(&sao_hook_cfg.systype, &sao_hook_cfg.platform.dongle);
if (FAILED(hr)) {
ExitProcess(EXIT_FAILURE);
}
hr = sao_touch_hook_init(&sao_hook_cfg.touch);
if (FAILED(hr)) {
ExitProcess(EXIT_FAILURE);
}
2024-10-06 20:37:20 +02:00
/* Initialize Unity native plugin DLL hooks
There seems to be an issue with other DLL hooks if `LoadLibraryW` is
hooked earlier in the `mu3hook` initialization. */
2023-09-18 10:05:22 +02:00
unity_hook_init();
gfx_hook_init(&sao_hook_cfg.gfx);
gfx_d3d11_hook_init(&sao_hook_cfg.gfx, sao_hook_mod);
gfx_dxgi_hook_init(&sao_hook_cfg.gfx, sao_hook_mod);
dprintf("--- End sao_pre_startup ---\n");
return sao_startup();
}
BOOL WINAPI DllMain(HMODULE mod, DWORD cause, void *ctx)
{
HRESULT hr;
if (cause != DLL_PROCESS_ATTACH) {
return TRUE;
}
sao_hook_mod = mod;
hr = process_hijack_startup(sao_pre_startup, &sao_startup);
if (!SUCCEEDED(hr)) {
dprintf("Failed to hijack process startup: %x\n", (int) hr);
}
return SUCCEEDED(hr);
}