mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2026-06-22 08:31:07 +00:00
Reformat to clang-format
This commit is contained in:
+11
-10
@@ -3,10 +3,9 @@
|
||||
/// Copyright (c) 2021-present Anonymous275 read the LICENSE file for more info.
|
||||
///
|
||||
|
||||
|
||||
#include "atomic_queue.h"
|
||||
#include "Memory/BeamNG.h"
|
||||
#include "Memory/Memory.h"
|
||||
#include "atomic_queue.h"
|
||||
|
||||
std::unique_ptr<atomic_queue<std::string, 1000>> Queue;
|
||||
|
||||
@@ -21,7 +20,8 @@ void BeamNG::EntryPoint() {
|
||||
Queue = std::make_unique<atomic_queue<std::string, 1000>>();
|
||||
uint32_t PID = Memory::GetPID();
|
||||
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(PID));
|
||||
GELua::FindAddresses();
|
||||
/*GameBaseAddr = Memory::GetModuleBase(GameModule);
|
||||
@@ -29,15 +29,15 @@ void BeamNG::EntryPoint() {
|
||||
OpenJITDetour = std::make_unique<Hook<def::lua_open_jit>>(GELua::lua_open_jit, lua_open_jit_D);
|
||||
OpenJITDetour->Enable();
|
||||
IPCFromLauncher = std::make_unique<IPC>(PID, 0x1900000);
|
||||
IPCToLauncher = std::make_unique<IPC>(PID+1, 0x1900000);
|
||||
IPCToLauncher = std::make_unique<IPC>(PID + 1, 0x1900000);
|
||||
IPCListener();
|
||||
}
|
||||
|
||||
int Core(lua_State* L) {
|
||||
if(lua_gettop(L) == 1) {
|
||||
if (lua_gettop(L) == 1) {
|
||||
size_t Size;
|
||||
const char* Data = GELua::lua_tolstring(L, 1, &Size);
|
||||
//Memory::Print("Core -> " + std::string(Data) + " - " + std::to_string(Size));
|
||||
// Memory::Print("Core -> " + std::string(Data) + " - " + std::to_string(Size));
|
||||
std::string msg(Data, Size);
|
||||
BeamNG::SendIPC("C" + msg);
|
||||
}
|
||||
@@ -45,10 +45,10 @@ int Core(lua_State* L) {
|
||||
}
|
||||
|
||||
int Game(lua_State* L) {
|
||||
if(lua_gettop(L) == 1) {
|
||||
if (lua_gettop(L) == 1) {
|
||||
size_t Size;
|
||||
const char* Data = GELua::lua_tolstring(L, 1, &Size);
|
||||
//Memory::Print("Game -> " + std::string(Data) + " - " + std::to_string(Size));
|
||||
// Memory::Print("Game -> " + std::string(Data) + " - " + std::to_string(Size));
|
||||
std::string msg(Data, Size);
|
||||
BeamNG::SendIPC("G" + msg);
|
||||
}
|
||||
@@ -80,13 +80,14 @@ void BeamNG::SendIPC(const std::string& Data) {
|
||||
|
||||
void BeamNG::IPCListener() {
|
||||
int TimeOuts = 0;
|
||||
while(TimeOuts < 20) {
|
||||
while (TimeOuts < 20) {
|
||||
IPCFromLauncher->receive();
|
||||
if (!IPCFromLauncher->receive_timed_out()) {
|
||||
TimeOuts = 0;
|
||||
Queue->push(IPCFromLauncher->msg());
|
||||
IPCFromLauncher->confirm_receive();
|
||||
} else TimeOuts++;
|
||||
} else
|
||||
TimeOuts++;
|
||||
}
|
||||
Memory::Print("IPC System shutting down");
|
||||
}
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
///
|
||||
|
||||
#include "Memory/Definitions.h"
|
||||
#include "lua/lj_strscan.h"
|
||||
#include "lua/lj_arch.h"
|
||||
#include "lua/lj_obj.h"
|
||||
#include "lua/lj_bc.h"
|
||||
#include "lua/lj_def.h"
|
||||
#include "lua/lj_gc.h"
|
||||
#include "lua/lj_bc.h"
|
||||
#include "lua/lj_obj.h"
|
||||
#include "lua/lj_strscan.h"
|
||||
|
||||
LUA_API int lua_gettop(lua_State *L) {
|
||||
LUA_API int lua_gettop(lua_State* L) {
|
||||
return (int)(L->top - L->base);
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
/// Copyright (c) 2021-present Anonymous275 read the LICENSE file for more info.
|
||||
///
|
||||
|
||||
#include "Memory/Patterns.h"
|
||||
#include "Memory/Memory.h"
|
||||
#include "Memory/GELua.h"
|
||||
#include "Memory/Memory.h"
|
||||
#include "Memory/Patterns.h"
|
||||
|
||||
const char* GameModule = "BeamNG.drive.x64.exe";
|
||||
const char* DllModule = "libbeamng.x64.dll";
|
||||
@@ -13,7 +13,7 @@ const char* DllModule = "libbeamng.x64.dll";
|
||||
std::string GetHex(uint64_t num) {
|
||||
char buffer[30];
|
||||
sprintf(buffer, "%llx", num);
|
||||
return std::string{buffer};
|
||||
return std::string { buffer };
|
||||
}
|
||||
|
||||
void GELua::FindAddresses() {
|
||||
|
||||
+10
-11
@@ -4,24 +4,25 @@
|
||||
///
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include "Memory/IPC.h"
|
||||
#include <windows.h>
|
||||
|
||||
IPC::IPC(uint32_t ID, size_t Size) noexcept : Size_(Size) {
|
||||
std::string Sem{"MP_S" + std::to_string(ID)},
|
||||
SemConf{"MP_SC" + std::to_string(ID)},
|
||||
Mem{"MP_IO" + std::to_string(ID)};
|
||||
IPC::IPC(uint32_t ID, size_t Size) noexcept
|
||||
: Size_(Size) {
|
||||
std::string Sem { "MP_S" + std::to_string(ID) },
|
||||
SemConf { "MP_SC" + std::to_string(ID) },
|
||||
Mem { "MP_IO" + std::to_string(ID) };
|
||||
|
||||
SemHandle_ = OpenSemaphoreA(SYNCHRONIZE | SEMAPHORE_MODIFY_STATE, FALSE, Sem.c_str());
|
||||
if(SemHandle_ == nullptr) {
|
||||
if (SemHandle_ == nullptr) {
|
||||
SemHandle_ = CreateSemaphoreA(nullptr, 0, 1, Sem.c_str());
|
||||
}
|
||||
SemConfHandle_ = OpenSemaphoreA(SYNCHRONIZE | SEMAPHORE_MODIFY_STATE, FALSE, SemConf.c_str());
|
||||
if(SemConfHandle_ == nullptr) {
|
||||
if (SemConfHandle_ == nullptr) {
|
||||
SemConfHandle_ = CreateSemaphoreA(nullptr, 0, 1, SemConf.c_str());
|
||||
}
|
||||
MemoryHandle_ = OpenFileMappingA(FILE_MAP_ALL_ACCESS, FALSE, Mem.c_str());
|
||||
if(MemoryHandle_ == nullptr) {
|
||||
if (MemoryHandle_ == nullptr) {
|
||||
MemoryHandle_ = CreateFileMappingA(INVALID_HANDLE_VALUE, nullptr, PAGE_READWRITE, 0, DWORD(Size), Mem.c_str());
|
||||
}
|
||||
Data_ = (char*)MapViewOfFile(MemoryHandle_, FILE_MAP_ALL_ACCESS, 0, 0, Size);
|
||||
@@ -82,11 +83,9 @@ IPC::~IPC() noexcept {
|
||||
}
|
||||
|
||||
bool IPC::mem_used(uint32_t MemID) noexcept {
|
||||
std::string Mem{"MP_IO" + std::to_string(MemID)};
|
||||
std::string Mem { "MP_IO" + std::to_string(MemID) };
|
||||
HANDLE MEM = OpenFileMappingA(FILE_MAP_ALL_ACCESS, FALSE, Mem.c_str());
|
||||
bool used = MEM != nullptr;
|
||||
UnmapViewOfFile(MEM);
|
||||
return used;
|
||||
}
|
||||
|
||||
|
||||
|
||||
+20
-20
@@ -7,9 +7,9 @@
|
||||
#undef UNICODE
|
||||
#include "Memory/Memory.h"
|
||||
#include "Memory/BeamNG.h"
|
||||
#include <psapi.h>
|
||||
#include <string>
|
||||
#include <tlhelp32.h>
|
||||
#include <psapi.h>
|
||||
|
||||
uint32_t Memory::GetBeamNGPID(const std::set<uint32_t>& BL) {
|
||||
SetLastError(0);
|
||||
@@ -17,21 +17,22 @@ uint32_t Memory::GetBeamNGPID(const std::set<uint32_t>& BL) {
|
||||
pe32.dwSize = sizeof(PROCESSENTRY32);
|
||||
HANDLE Snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
|
||||
|
||||
if(Process32First(Snapshot, &pe32)) {
|
||||
do{
|
||||
if(std::string("BeamNG.drive.x64.exe") == pe32.szExeFile
|
||||
&& BL.find(pe32.th32ProcessID) == BL.end()
|
||||
&& BL.find(pe32.th32ParentProcessID) == BL.end()) {
|
||||
if (Process32First(Snapshot, &pe32)) {
|
||||
do {
|
||||
if (std::string("BeamNG.drive.x64.exe") == pe32.szExeFile
|
||||
&& BL.find(pe32.th32ProcessID) == BL.end()
|
||||
&& BL.find(pe32.th32ParentProcessID) == BL.end()) {
|
||||
break;
|
||||
}
|
||||
}while(Process32Next(Snapshot, &pe32));
|
||||
} while (Process32Next(Snapshot, &pe32));
|
||||
}
|
||||
|
||||
if(Snapshot != INVALID_HANDLE_VALUE) {
|
||||
if (Snapshot != INVALID_HANDLE_VALUE) {
|
||||
CloseHandle(Snapshot);
|
||||
}
|
||||
|
||||
if(GetLastError() != 0)return 0;
|
||||
if (GetLastError() != 0)
|
||||
return 0;
|
||||
return pe32.th32ProcessID;
|
||||
}
|
||||
|
||||
@@ -44,24 +45,23 @@ uint32_t Memory::GetPID() {
|
||||
}
|
||||
|
||||
uint64_t Memory::FindPattern(const char* module, const char* Pattern[]) {
|
||||
MODULEINFO mInfo{nullptr};
|
||||
MODULEINFO mInfo { nullptr };
|
||||
GetModuleInformation(GetCurrentProcess(), GetModuleHandleA(module), &mInfo, sizeof(MODULEINFO));
|
||||
auto base = uint64_t(mInfo.lpBaseOfDll);
|
||||
auto size = uint32_t(mInfo.SizeOfImage);
|
||||
auto len = strlen(Pattern[1]);
|
||||
for(auto i = 0; i < size - len; i++) {
|
||||
for (auto i = 0; i < size - len; i++) {
|
||||
bool found = true;
|
||||
for(auto j = 0; j < len && found; j++) {
|
||||
found &= Pattern[1][j] == '?' || Pattern[0][j] == *(char*)(base+i+j);
|
||||
for (auto j = 0; j < len && found; j++) {
|
||||
found &= Pattern[1][j] == '?' || Pattern[0][j] == *(char*)(base + i + j);
|
||||
}
|
||||
if(found) {
|
||||
return base+i;
|
||||
if (found) {
|
||||
return base + i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void* operator new(size_t size) {
|
||||
return GlobalAlloc(GPTR, size);
|
||||
}
|
||||
@@ -98,11 +98,11 @@ void Memory::Inject(uint32_t PID) {
|
||||
|
||||
auto relocationTable = (PIMAGE_BASE_RELOCATION)((DWORD_PTR)localImage + ntHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress);
|
||||
PDWORD_PTR patchedAddress;
|
||||
while (relocationTable->SizeOfBlock > 0){
|
||||
while (relocationTable->SizeOfBlock > 0) {
|
||||
DWORD relocationEntriesCount = (relocationTable->SizeOfBlock - sizeof(IMAGE_BASE_RELOCATION)) / sizeof(USHORT);
|
||||
auto relocationRVA = (PBASE_RELOCATION_ENTRY)(relocationTable + 1);
|
||||
for (uint32_t i = 0; i < relocationEntriesCount; i++){
|
||||
if (relocationRVA[i].Offset){
|
||||
for (uint32_t i = 0; i < relocationEntriesCount; i++) {
|
||||
if (relocationRVA[i].Offset) {
|
||||
patchedAddress = PDWORD_PTR(DWORD_PTR(localImage) + relocationTable->VirtualAddress + relocationRVA[i].Offset);
|
||||
*patchedAddress += deltaImageBase;
|
||||
}
|
||||
@@ -110,7 +110,7 @@ void Memory::Inject(uint32_t PID) {
|
||||
relocationTable = PIMAGE_BASE_RELOCATION(DWORD_PTR(relocationTable) + relocationTable->SizeOfBlock);
|
||||
}
|
||||
WriteProcessMemory(targetProcess, targetImage, localImage, ntHeader->OptionalHeader.SizeOfImage, nullptr);
|
||||
CreateRemoteThread(targetProcess,nullptr,0,(LPTHREAD_START_ROUTINE)((DWORD_PTR)EntryPoint + deltaImageBase),nullptr,0,nullptr);
|
||||
CreateRemoteThread(targetProcess, nullptr, 0, (LPTHREAD_START_ROUTINE)((DWORD_PTR)EntryPoint + deltaImageBase), nullptr, 0, nullptr);
|
||||
CloseHandle(targetProcess);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user