Example #1
0
void LoaderGUI::ConnectSlots(BoIInjector &injector)
{
    QObject::connect(&injector, SIGNAL(InjectionStatus(InjectStatus)),
                     this, SLOT(OnInjectionStatusChange(InjectStatus)));
    QObject::connect(&injector, SIGNAL(FatalError(std::string)),
                     this, SLOT(OnFatalError(std::string)));
}
Example #2
0
void BoIInjector::InjectorThread()
{
    try
    {
        while (!stop_injector_)
        {
            if (IsBoIRunning())
            {
                LOG(INFO) << "BoI process found, time to inject...";

                // Set-up the DLL message queue (for IPC)
                MHUD::MsgQueue::Remove(MSG_QUEUE_APP_TO_DLL);
                MHUD::MsgQueue::Remove(MSG_QUEUE_DLL_TO_APP);
                app_msg_queue_ = MHUD::MsgQueue::GetInstance(MSG_QUEUE_APP_TO_DLL);
                dll_msg_queue_ = MHUD::MsgQueue::GetInstance(MSG_QUEUE_DLL_TO_APP);
                std::thread handle_dll_msgs = std::thread(&BoIInjector::HandleDllMsgs, this);
                handle_dll_msgs.detach();

                // Send the preferences message ready for the DLL
                SendNewPrefs(MHUD::Options::ReadCfgFile(CFG_FILENAME));

                // Inject DLL
                isaac_process_ = BoIProcess::GetInstance();
                isaac_process_->HookBoIProcess();

                // Notify that we're injected
                LOG(INFO) << "BoI process injected successfully.";
                emit InjectionStatus(InjectStatus(InjectStatus::Result::OK));

                // Just sleep until Isaac closes or injector is quitting
                while (isaac_process_->IsRunning() && !stop_injector_)
                {
                    if (!isaac_process_->MHUD2Active())  // MHUD2 should not unload until we want it to (or Isaac closes)
                        throw std::runtime_error("Error occurred within injected DLL. Check MHUD2.log for details.");

                    std::this_thread::sleep_for(std::chrono::milliseconds(500));
                }

                // Eject our DLLs (if they are still in the running BoI process)
                LOG(INFO) << "BoI process closed or MissingHUD2 requested quit.";
                BoIProcess::Close();

                // Clean-up DLL message queue
                app_msg_queue_ = nullptr;
                dll_msg_queue_ = nullptr;
                MHUD::MsgQueue::Remove(MSG_QUEUE_APP_TO_DLL);
                MHUD::MsgQueue::Remove(MSG_QUEUE_DLL_TO_APP);
            }
            else
            {
                emit InjectionStatus(InjectStatus(InjectStatus::Result::NOT_FOUND));
            }

            std::this_thread::sleep_for(std::chrono::milliseconds(500));
        }
    }
    catch (std::runtime_error &e)
    {
        LOG(ERROR) << "Injection thread error occured: " << e.what() << " (Error Code: " << GetLastError() << ")";
        emit FatalError(e.what());
    }
    catch (boost::interprocess::interprocess_exception &ie)
    {
        LOG(ERROR) << "boost::interprocess communication error occured: " << ie.what() << " (Error Code: " << GetLastError() << ")";
        emit FatalError("boost::interprocesscommunication error occured. Check MHUD2.log for details.");
    }
    catch (...)
    {
        LOG(ERROR) << "Unknown error occured. " << " (Error Code: " << GetLastError() << ")";
        emit FatalError("Unknown error occured.");
    }
}