#include #include #include #include #include #include #include #include #include HMODULE this_module; size_t unload_ctr = 0; void unload_ctr_inc() { unload_ctr++; } void unload_ctr_dec() { unload_ctr--; if (unload_ctr == 0) { void *pFreeLibrary = GetProcAddress(GetModuleHandleA("kernel32.dll"), "FreeLibrary"); CreateThread(NULL, 0, pFreeLibrary, this_module, 0, NULL); } } void request_restart() { wchar_t restartFlagFile[MAX_PATH]; GetTempPathW(MAX_PATH, restartFlagFile); wcscat(restartFlagFile, L"jadeite\\restart_flag"); HANDLE hRestartFlag = CreateFileW(restartFlagFile, FILE_WRITE_ACCESS, FILE_SHARE_READ, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL); CloseHandle(hRestartFlag); } static void _run_game(struct game_data *game, wchar_t *txFile) { // Create fake ACE driver files ace_fake_driver_files(); // Load both ACE modules HMODULE baseModule = ace_load_base_module(game); ace_load_driver_module(); // ...magic core_setup_patcher(game, baseModule, txFile); // Load the UnityPlayer module and invoke the callback HMODULE unityModule = LoadLibraryA("UnityPlayer.dll"); INVOKE_CALLBACK(game->unityplayer_callback, unityModule); } static void _run_tx(struct game_data *game, wchar_t *txFile) { // ...more magic size_t tableSize; void *table = core_perform_tx(game, &tableSize); // Save to file utils_create_parent_dirs(txFile); utils_save_to_file(txFile, table, tableSize); // Cleanup free(table); // The file should now exist: restart and launch the game request_restart(); exit(0); } BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved) { // Only listen to attach if (reason != DLL_PROCESS_ATTACH) { return TRUE; } this_module = instance; // Dynamically link functions from ntdll ntdll_link(); // Detect which game the user is trying to run struct game_data game; game_detect(&game); // Get required table file path wchar_t txFile[MAX_PATH]; tx_table_file(&game, txFile); if (utils_path_exists(txFile)) { _run_game(&game, txFile); } else { _run_tx(&game, txFile); } return TRUE; }