mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2025-08-17 16:57:11 +00:00
Merge branch 'BeamMP:v3' into v3
This commit is contained in:
commit
b756b00503
@ -43,7 +43,7 @@ add_executable(${PROJECT_NAME}
|
|||||||
#src/gui/Gui.cpp
|
#src/gui/Gui.cpp
|
||||||
include/Json.h
|
include/Json.h
|
||||||
src/gui/gifs.cpp src/gui/gifs.h
|
src/gui/gifs.cpp src/gui/gifs.h
|
||||||
src/Network/Http.cpp include/Http.h
|
src/Network/HttpAPI.cpp include/HttpAPI.h
|
||||||
src/Network/Server.cpp include/Server.h
|
src/Network/Server.cpp include/Server.h
|
||||||
src/Network/Login.cpp src/Network/Update.cpp
|
src/Network/Login.cpp src/Network/Update.cpp
|
||||||
src/Network/Compressor.cpp include/Compressor.h
|
src/Network/Compressor.cpp include/Compressor.h
|
||||||
|
56
include/atomic_queue.h
Normal file
56
include/atomic_queue.h
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
//
|
||||||
|
// Created by Anonymous275 on 24/07/22.
|
||||||
|
//
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include <semaphore>
|
||||||
|
#include <queue>
|
||||||
|
|
||||||
|
template <class T, size_t Size>
|
||||||
|
class atomic_queue {
|
||||||
|
public:
|
||||||
|
bool try_pop(T& val) {
|
||||||
|
lock_guard guard(semaphore);
|
||||||
|
if(queue.empty())return false;
|
||||||
|
val = queue.front();
|
||||||
|
queue.pop();
|
||||||
|
full.release();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void push(const T& val) {
|
||||||
|
check_full();
|
||||||
|
lock_guard guard(semaphore);
|
||||||
|
queue.push(val);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t size() {
|
||||||
|
lock_guard guard(semaphore);
|
||||||
|
return queue.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool empty() {
|
||||||
|
lock_guard guard(semaphore);
|
||||||
|
return queue.empty();
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
void check_full() {
|
||||||
|
if(size() >= Size) {
|
||||||
|
full.acquire();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
struct lock_guard {
|
||||||
|
explicit lock_guard(std::binary_semaphore& lock) : lock(lock){
|
||||||
|
lock.acquire();
|
||||||
|
}
|
||||||
|
~lock_guard() {
|
||||||
|
lock.release();
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
std::binary_semaphore& lock;
|
||||||
|
};
|
||||||
|
std::binary_semaphore semaphore{1}, full{0};
|
||||||
|
std::queue<T> queue{};
|
||||||
|
};
|
||||||
|
|
@ -7,8 +7,9 @@
|
|||||||
#include "Memory/Memory.h"
|
#include "Memory/Memory.h"
|
||||||
#include "Memory/BeamNG.h"
|
#include "Memory/BeamNG.h"
|
||||||
#include "Launcher.h"
|
#include "Launcher.h"
|
||||||
|
#include "HttpAPI.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include "Http.h"
|
|
||||||
|
|
||||||
void Launcher::HandleIPC(const std::string& Data) {
|
void Launcher::HandleIPC(const std::string& Data) {
|
||||||
char Code = Data.at(0), SubCode = 0;
|
char Code = Data.at(0), SubCode = 0;
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
#include "Launcher.h"
|
#include "Launcher.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include <csignal>
|
#include <csignal>
|
||||||
#include "Http.h"
|
#include "HttpAPI.h"
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <shellapi.h>
|
#include <shellapi.h>
|
||||||
#include <ShlObj.h>
|
#include <ShlObj.h>
|
||||||
@ -125,6 +125,7 @@ void Launcher::WaitForGame() {
|
|||||||
std::this_thread::sleep_for(std::chrono::seconds(2));
|
std::this_thread::sleep_for(std::chrono::seconds(2));
|
||||||
}
|
}
|
||||||
LOG(INFO) << "Game process was lost";
|
LOG(INFO) << "Game process was lost";
|
||||||
|
GamePID = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Launcher::ListenIPC() {
|
void Launcher::ListenIPC() {
|
||||||
|
@ -4,11 +4,13 @@
|
|||||||
///
|
///
|
||||||
|
|
||||||
|
|
||||||
#include "atomic_queue/atomic_queue.h"
|
#include "atomic_queue.h"
|
||||||
#include "Memory/BeamNG.h"
|
#include "Memory/BeamNG.h"
|
||||||
#include "Memory/Memory.h"
|
#include "Memory/Memory.h"
|
||||||
|
|
||||||
atomic_queue::AtomicQueue2<std::string, 1000> AtomicQueue;
|
//atomic_queue::AtomicQueue2<std::string, 1000> AtomicQueue;
|
||||||
|
std::unique_ptr<atomic_queue<std::string, 1000>> Queue;
|
||||||
|
|
||||||
|
|
||||||
int BeamNG::lua_open_jit_D(lua_State* State) {
|
int BeamNG::lua_open_jit_D(lua_State* State) {
|
||||||
Memory::Print("Got lua State");
|
Memory::Print("Got lua State");
|
||||||
@ -18,6 +20,7 @@ int BeamNG::lua_open_jit_D(lua_State* State) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void BeamNG::EntryPoint() {
|
void BeamNG::EntryPoint() {
|
||||||
|
Queue = std::make_unique<atomic_queue<std::string, 1000>>();
|
||||||
auto status = MH_Initialize();
|
auto status = MH_Initialize();
|
||||||
if(status != MH_OK)Memory::Print(std::string("MH Error -> ") + MH_StatusToString(status));
|
if(status != MH_OK)Memory::Print(std::string("MH Error -> ") + MH_StatusToString(status));
|
||||||
Memory::Print("PID : " + std::to_string(Memory::GetPID()));
|
Memory::Print("PID : " + std::to_string(Memory::GetPID()));
|
||||||
@ -55,7 +58,7 @@ int Game(lua_State* L) {
|
|||||||
|
|
||||||
int LuaPop(lua_State* L) {
|
int LuaPop(lua_State* L) {
|
||||||
std::string MSG;
|
std::string MSG;
|
||||||
if (AtomicQueue.try_pop(MSG)) {
|
if (Queue->try_pop(MSG)) {
|
||||||
GELua::lua_push_fstring(L, "%s", MSG.c_str());
|
GELua::lua_push_fstring(L, "%s", MSG.c_str());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -82,7 +85,7 @@ void BeamNG::IPCListener() {
|
|||||||
IPCFromLauncher->receive();
|
IPCFromLauncher->receive();
|
||||||
if (!IPCFromLauncher->receive_timed_out()) {
|
if (!IPCFromLauncher->receive_timed_out()) {
|
||||||
TimeOuts = 0;
|
TimeOuts = 0;
|
||||||
AtomicQueue.push(IPCFromLauncher->msg());
|
Queue->push(IPCFromLauncher->msg());
|
||||||
IPCFromLauncher->confirm_receive();
|
IPCFromLauncher->confirm_receive();
|
||||||
} else TimeOuts++;
|
} else TimeOuts++;
|
||||||
}
|
}
|
||||||
|
@ -5,10 +5,10 @@
|
|||||||
#define CPPHTTPLIB_OPENSSL_SUPPORT
|
#define CPPHTTPLIB_OPENSSL_SUPPORT
|
||||||
#include <cpp-httplib/httplib.h>
|
#include <cpp-httplib/httplib.h>
|
||||||
#include "Launcher.h"
|
#include "Launcher.h"
|
||||||
|
#include "HttpAPI.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include "Http.h"
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
@ -4,8 +4,8 @@
|
|||||||
///
|
///
|
||||||
|
|
||||||
#include "Launcher.h"
|
#include "Launcher.h"
|
||||||
|
#include "HttpAPI.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include "Http.h"
|
|
||||||
#include "Json.h"
|
#include "Json.h"
|
||||||
|
|
||||||
void UpdateKey(const std::string& newKey){
|
void UpdateKey(const std::string& newKey){
|
||||||
|
@ -4,8 +4,8 @@
|
|||||||
///
|
///
|
||||||
|
|
||||||
#include "Launcher.h"
|
#include "Launcher.h"
|
||||||
|
#include "HttpAPI.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include "Http.h"
|
|
||||||
#include "Json.h"
|
#include "Json.h"
|
||||||
|
|
||||||
VersionParser::VersionParser(const std::string &from_string) {
|
VersionParser::VersionParser(const std::string &from_string) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user