mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2025-07-02 16:06:35 +00:00
- fixed IPC timeout on inactivity
This commit is contained in:
parent
4a4204932d
commit
58e9fef53f
@ -14,7 +14,7 @@ class BeamNG {
|
|||||||
public:
|
public:
|
||||||
static void EntryPoint();
|
static void EntryPoint();
|
||||||
static void SendIPC(const std::string& Data);
|
static void SendIPC(const std::string& Data);
|
||||||
|
static inline bool Terminate = false;
|
||||||
private:
|
private:
|
||||||
static inline std::unique_ptr<Hook<def::update_function>> UpdateDetour;
|
static inline std::unique_ptr<Hook<def::update_function>> UpdateDetour;
|
||||||
static inline std::unique_ptr<Hook<def::lua_open_jit>> OpenJITDetour;
|
static inline std::unique_ptr<Hook<def::lua_open_jit>> OpenJITDetour;
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include "Memory/BeamNG.h"
|
#include "Memory/BeamNG.h"
|
||||||
#include "Memory/Memory.h"
|
#include "Memory/Memory.h"
|
||||||
#include "atomic_queue.h"
|
#include "atomic_queue.h"
|
||||||
|
#include <csignal>
|
||||||
|
|
||||||
std::unique_ptr<atomic_queue<std::string, 1000>> RCVQueue, SendQueue;
|
std::unique_ptr<atomic_queue<std::string, 1000>> RCVQueue, SendQueue;
|
||||||
|
|
||||||
@ -28,30 +29,39 @@ uint64_t BeamNG::update_D(lua_State* State) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SignalHandler(int sig) {
|
||||||
|
Memory::Print( "Got termination signal (" + std::to_string(sig) +")");
|
||||||
|
BeamNG::Terminate = true;
|
||||||
|
}
|
||||||
|
|
||||||
void BeamNG::EntryPoint() {
|
void BeamNG::EntryPoint() {
|
||||||
RCVQueue = std::make_unique<atomic_queue<std::string, 1000>>();
|
signal(SIGINT, SignalHandler);
|
||||||
SendQueue = std::make_unique<atomic_queue<std::string, 1000>>();
|
signal(SIGTERM, SignalHandler);
|
||||||
uint32_t PID = Memory::GetPID();
|
signal(SIGABRT, SignalHandler);
|
||||||
auto status = MH_Initialize();
|
signal(SIGBREAK, SignalHandler);
|
||||||
if (status != MH_OK)
|
RCVQueue = std::make_unique<atomic_queue<std::string, 1000>>();
|
||||||
Memory::Print(std::string("MH Error -> ") + MH_StatusToString(status));
|
SendQueue = std::make_unique<atomic_queue<std::string, 1000>>();
|
||||||
Memory::Print("PID : " + std::to_string(PID));
|
uint32_t PID = Memory::GetPID();
|
||||||
GELua::FindAddresses();
|
auto status = MH_Initialize();
|
||||||
/*GameBaseAddr = Memory::GetModuleBase(GameModule);
|
if (status != MH_OK)
|
||||||
DllBaseAddr = Memory::GetModuleBase(DllModule);*/
|
Memory::Print(std::string("MH Error -> ") + MH_StatusToString(status));
|
||||||
|
Memory::Print("PID : " + std::to_string(PID));
|
||||||
|
GELua::FindAddresses();
|
||||||
|
/*GameBaseAddr = Memory::GetModuleBase(GameModule);
|
||||||
|
DllBaseAddr = Memory::GetModuleBase(DllModule);*/
|
||||||
|
|
||||||
UpdateDetour = std::make_unique<Hook<def::update_function>>(
|
UpdateDetour = std::make_unique<Hook<def::update_function>>(
|
||||||
GELua::update_function, update_D);
|
GELua::update_function, update_D);
|
||||||
UpdateDetour->Enable();
|
UpdateDetour->Enable();
|
||||||
|
|
||||||
OpenJITDetour = std::make_unique<Hook<def::lua_open_jit>>(
|
OpenJITDetour = std::make_unique<Hook<def::lua_open_jit>>(
|
||||||
GELua::lua_open_jit, lua_open_jit_D);
|
GELua::lua_open_jit, lua_open_jit_D);
|
||||||
OpenJITDetour->Enable();
|
OpenJITDetour->Enable();
|
||||||
IPCFromLauncher = std::make_unique<IPC>(PID, 0x1900000);
|
IPCFromLauncher = std::make_unique<IPC>(PID, 0x1900000);
|
||||||
IPCToLauncher = std::make_unique<IPC>(PID + 1, 0x1900000);
|
IPCToLauncher = std::make_unique<IPC>(PID + 1, 0x1900000);
|
||||||
CreateThread(nullptr, 0, LPTHREAD_START_ROUTINE(IPCSender), nullptr, 0,
|
CreateThread(nullptr, 0, LPTHREAD_START_ROUTINE(IPCSender), nullptr, 0,
|
||||||
nullptr);
|
nullptr);
|
||||||
IPCListener();
|
IPCListener();
|
||||||
}
|
}
|
||||||
|
|
||||||
int Core(lua_State* L) {
|
int Core(lua_State* L) {
|
||||||
@ -102,30 +112,25 @@ void BeamNG::SendIPC(const std::string& Data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void BeamNG::IPCListener() {
|
void BeamNG::IPCListener() {
|
||||||
int TimeOuts = 0;
|
while (!Terminate) {
|
||||||
while (TimeOuts < 20) {
|
|
||||||
IPCFromLauncher->receive();
|
IPCFromLauncher->receive();
|
||||||
if (!IPCFromLauncher->receive_timed_out()) {
|
if (!IPCFromLauncher->receive_timed_out()) {
|
||||||
TimeOuts = 0;
|
|
||||||
RCVQueue->push(IPCFromLauncher->msg());
|
RCVQueue->push(IPCFromLauncher->msg());
|
||||||
IPCFromLauncher->confirm_receive();
|
IPCFromLauncher->confirm_receive();
|
||||||
} else TimeOuts++;
|
}
|
||||||
}
|
}
|
||||||
Memory::Print("IPC Listener System shutting down (timeout)");
|
Memory::Print("IPC Listener System shutting down (terminate)");
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t BeamNG::IPCSender(void* LP) {
|
uint32_t BeamNG::IPCSender(void* LP) {
|
||||||
std::string result;
|
std::string result;
|
||||||
int TimeOuts = 0;
|
while (!Terminate) {
|
||||||
while (TimeOuts < 20) {
|
|
||||||
if (SendQueue->try_pop(result)) {
|
if (SendQueue->try_pop(result)) {
|
||||||
IPCToLauncher->send(result);
|
IPCToLauncher->send(result);
|
||||||
if (!IPCToLauncher->send_timed_out()) TimeOuts = 0;
|
|
||||||
else TimeOuts++;
|
|
||||||
} else {
|
} else {
|
||||||
Sleep(1); //TODO look into possibly have it wake up on a new message instead
|
Sleep(1); //TODO look into possibly have it wake up on a new message instead
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Memory::Print("IPC Sender System shutting down (timeout)");
|
Memory::Print("IPC Sender System shutting down (terminate)");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user