mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2026-06-22 08:31:07 +00:00
clang format
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
---
|
||||
BasedOnStyle: Google
|
||||
AccessModifierOffset: 0
|
||||
AlignConsecutiveAssignments: Consecutive
|
||||
AlignEscapedNewlines: Right
|
||||
AlignTrailingComments: true
|
||||
AllowShortBlocksOnASingleLine: Empty
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: Inline
|
||||
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
|
||||
AllowShortLoopsOnASingleLine: true
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakTemplateDeclarations: Yes
|
||||
BreakBeforeInheritanceComma: false
|
||||
BreakConstructorInitializers: AfterColon
|
||||
Cpp11BracedListStyle: true
|
||||
DerivePointerAlignment: false
|
||||
FixNamespaceComments: false
|
||||
IncludeBlocks: Preserve
|
||||
IndentCaseLabels: true
|
||||
IndentWidth: 3
|
||||
IndentAccessModifiers: false
|
||||
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||
Language: Cpp
|
||||
MaxEmptyLinesToKeep: 1
|
||||
NamespaceIndentation: All
|
||||
PointerAlignment: Left
|
||||
ReflowComments: true
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceAfterTemplateKeyword: false
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesInAngles: Never
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInContainerLiterals: true
|
||||
SpacesInParentheses: false
|
||||
SpacesInSquareBrackets: false
|
||||
Standard: Latest
|
||||
TabWidth: 2
|
||||
UseTab: Never
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <string>
|
||||
|
||||
class Zlib {
|
||||
public:
|
||||
public:
|
||||
static std::string DeComp(std::string Compressed);
|
||||
static std::string Comp(std::string Data);
|
||||
};
|
||||
+2
-2
@@ -7,12 +7,12 @@
|
||||
#include <string>
|
||||
|
||||
class HTTP {
|
||||
public:
|
||||
public:
|
||||
static bool Download(const std::string& IP, const std::string& Path);
|
||||
static std::string Post(const std::string& IP, const std::string& Fields);
|
||||
static std::string Get(const std::string& IP);
|
||||
static bool ProgressBar(size_t c, size_t t);
|
||||
|
||||
public:
|
||||
public:
|
||||
static bool isDownload;
|
||||
};
|
||||
+30
-30
@@ -4,10 +4,10 @@
|
||||
///
|
||||
|
||||
#pragma once
|
||||
#include "Memory/IPC.h"
|
||||
#include "Server.h"
|
||||
#include <filesystem>
|
||||
#include <thread>
|
||||
#include "Memory/IPC.h"
|
||||
#include "Server.h"
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
@@ -20,11 +20,11 @@ struct VersionParser {
|
||||
};
|
||||
|
||||
class Launcher {
|
||||
public: // constructors
|
||||
public: // constructors
|
||||
Launcher(int argc, char* argv[]);
|
||||
~Launcher();
|
||||
|
||||
public: // available functions
|
||||
public: // available functions
|
||||
static void StaticAbort(Launcher* Instance = nullptr);
|
||||
std::string Login(const std::string& fields);
|
||||
void SendIPC(const std::string& Data, bool core = true);
|
||||
@@ -36,7 +36,7 @@ public: // available functions
|
||||
void CheckKey();
|
||||
void SetupMOD();
|
||||
|
||||
public: // Getters and Setters
|
||||
public: // Getters and Setters
|
||||
void setDiscordMessage(const std::string& message);
|
||||
static void setExit(bool exit) noexcept;
|
||||
const std::string& getFullVersion();
|
||||
@@ -47,7 +47,7 @@ public: // Getters and Setters
|
||||
const std::string& getVersion();
|
||||
static bool getExit() noexcept;
|
||||
|
||||
private: // functions
|
||||
private: // functions
|
||||
void HandleIPC(const std::string& Data);
|
||||
std::string GetLocalAppdata();
|
||||
void UpdatePresence();
|
||||
@@ -61,33 +61,33 @@ private: // functions
|
||||
void ListenIPC();
|
||||
void Abort();
|
||||
|
||||
private: // variables
|
||||
uint32_t GamePID { 0 };
|
||||
private: // variables
|
||||
uint32_t GamePID{0};
|
||||
bool EnableUI = true;
|
||||
int64_t DiscordTime {};
|
||||
int64_t DiscordTime{};
|
||||
bool LoginAuth = false;
|
||||
fs::path CurrentPath {};
|
||||
std::string BeamRoot {};
|
||||
std::string UserRole {};
|
||||
std::string PublicKey {};
|
||||
std::thread IPCSystem {};
|
||||
std::thread DiscordRPC {};
|
||||
std::string MPUserPath {};
|
||||
std::string BeamVersion {};
|
||||
std::string BeamUserPath {};
|
||||
std::string DiscordMessage {};
|
||||
std::string Version { "2.0" };
|
||||
Server ServerHandler { this };
|
||||
std::string TargetBuild { "default" };
|
||||
static inline std::atomic<bool> Shutdown { false }, Exit { false };
|
||||
std::string FullVersion { Version + ".99" };
|
||||
VersionParser SupportedVersion { "0.25.4.0" };
|
||||
std::unique_ptr<IPC> IPCToGame {};
|
||||
std::unique_ptr<IPC> IPCFromGame {};
|
||||
fs::path CurrentPath{};
|
||||
std::string BeamRoot{};
|
||||
std::string UserRole{};
|
||||
std::string PublicKey{};
|
||||
std::thread IPCSystem{};
|
||||
std::thread DiscordRPC{};
|
||||
std::string MPUserPath{};
|
||||
std::string BeamVersion{};
|
||||
std::string BeamUserPath{};
|
||||
std::string DiscordMessage{};
|
||||
std::string Version{"2.0"};
|
||||
Server ServerHandler{this};
|
||||
std::string TargetBuild{"default"};
|
||||
static inline std::atomic<bool> Shutdown{false}, Exit{false};
|
||||
std::string FullVersion{Version + ".99"};
|
||||
VersionParser SupportedVersion{"0.25.4.0"};
|
||||
std::unique_ptr<IPC> IPCToGame{};
|
||||
std::unique_ptr<IPC> IPCFromGame{};
|
||||
};
|
||||
|
||||
class ShutdownException : public std::runtime_error {
|
||||
public:
|
||||
explicit ShutdownException(const std::string& message)
|
||||
: runtime_error(message) {};
|
||||
public:
|
||||
explicit ShutdownException(const std::string& message) :
|
||||
runtime_error(message){};
|
||||
};
|
||||
|
||||
+1
-1
@@ -8,6 +8,6 @@
|
||||
#undef min
|
||||
#undef max
|
||||
class Log {
|
||||
public:
|
||||
public:
|
||||
static void Init();
|
||||
};
|
||||
|
||||
@@ -4,17 +4,18 @@
|
||||
///
|
||||
|
||||
#pragma once
|
||||
#include "Memory/Hook.h"
|
||||
#include "Memory/GELua.h"
|
||||
#include "Memory/IPC.h"
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include "Memory/GELua.h"
|
||||
#include "Memory/Hook.h"
|
||||
#include "Memory/IPC.h"
|
||||
|
||||
class BeamNG {
|
||||
public:
|
||||
public:
|
||||
static void EntryPoint();
|
||||
static void SendIPC(const std::string& Data);
|
||||
private:
|
||||
|
||||
private:
|
||||
static inline std::unique_ptr<Hook<def::GEUpdate>> TickCountDetour;
|
||||
static inline std::unique_ptr<Hook<def::lua_open_jit>> OpenJITDetour;
|
||||
static inline std::unique_ptr<IPC> IPCFromLauncher;
|
||||
@@ -23,6 +24,7 @@ private:
|
||||
static inline uint64_t DllBaseAddr;
|
||||
static int lua_open_jit_D(lua_State* State);
|
||||
static void RegisterGEFunctions();
|
||||
// static int GetTickCount_D(void* GEState, void* Param2, void* Param3, void* Param4);
|
||||
// static int GetTickCount_D(void* GEState, void* Param2, void* Param3, void*
|
||||
// Param4);
|
||||
static void IPCListener();
|
||||
};
|
||||
|
||||
@@ -8,9 +8,10 @@
|
||||
|
||||
typedef struct lua_State lua_State;
|
||||
typedef int (*lua_CFunction)(lua_State*);
|
||||
extern int lua_gettop(lua_State *L);
|
||||
extern int lua_gettop(lua_State* L);
|
||||
namespace def {
|
||||
typedef int (*GEUpdate)(void* Param1, void* Param2, void* Param3, void* Param4);
|
||||
typedef int (*GEUpdate)(void* Param1, void* Param2, void* Param3,
|
||||
void* Param4);
|
||||
typedef uint32_t (*GetTickCount)();
|
||||
typedef int (*lua_open_jit)(lua_State* L);
|
||||
typedef void (*lua_get_field)(lua_State* L, int idx, const char* k);
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include "Definitions.h"
|
||||
|
||||
class GELua {
|
||||
public:
|
||||
public:
|
||||
static void FindAddresses();
|
||||
static inline def::GEUpdate GEUpdate;
|
||||
static inline def::lua_settop lua_settop;
|
||||
@@ -37,7 +37,8 @@ namespace GELuaTable {
|
||||
inline void EndEntry(lua_State* L) {
|
||||
GELua::lua_settable(L, -3);
|
||||
}
|
||||
inline void InsertFunction(lua_State* L, const char* name, lua_CFunction func) {
|
||||
inline void InsertFunction(lua_State* L, const char* name,
|
||||
lua_CFunction func) {
|
||||
BeginEntry(L, name);
|
||||
GELua::lua_pushcclosure(L, func, 0);
|
||||
EndEntry(L);
|
||||
|
||||
+14
-11
@@ -3,30 +3,32 @@
|
||||
/// Copyright (c) 2021-present Anonymous275 read the LICENSE file for more info.
|
||||
///
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include "Memory/Memory.h"
|
||||
#include <MinHook.h>
|
||||
#include "Memory/Memory.h"
|
||||
|
||||
#pragma once
|
||||
template <class FuncType>
|
||||
template<class FuncType>
|
||||
class Hook {
|
||||
FuncType targetPtr;
|
||||
FuncType detourFunc;
|
||||
bool Attached = false;
|
||||
public:
|
||||
|
||||
public:
|
||||
Hook(FuncType src, FuncType dest) : targetPtr(src), detourFunc(dest) {
|
||||
auto status = MH_CreateHook((void*)targetPtr, (void*)detourFunc, (void**)&Original);
|
||||
if(status != MH_OK) {
|
||||
auto status =
|
||||
MH_CreateHook((void*)targetPtr, (void*)detourFunc, (void**)&Original);
|
||||
if (status != MH_OK) {
|
||||
Memory::Print(std::string("MH Error -> ") + MH_StatusToString(status));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void Enable() {
|
||||
if(!Attached){
|
||||
if (!Attached) {
|
||||
auto status = MH_EnableHook((void*)targetPtr);
|
||||
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));
|
||||
return;
|
||||
}
|
||||
Attached = true;
|
||||
@@ -34,10 +36,11 @@ public:
|
||||
}
|
||||
|
||||
void Disable() {
|
||||
if(Attached){
|
||||
if (Attached) {
|
||||
auto status = MH_DisableHook((void*)targetPtr);
|
||||
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));
|
||||
return;
|
||||
}
|
||||
Attached = false;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <string>
|
||||
|
||||
class IPC {
|
||||
public:
|
||||
public:
|
||||
IPC() = default;
|
||||
IPC(uint32_t ID, size_t Size) noexcept;
|
||||
[[nodiscard]] size_t size() const noexcept;
|
||||
@@ -22,7 +22,8 @@ public:
|
||||
void receive() noexcept;
|
||||
~IPC() noexcept;
|
||||
static bool mem_used(uint32_t MemID) noexcept;
|
||||
private:
|
||||
|
||||
private:
|
||||
void* SemConfHandle_;
|
||||
void* MemoryHandle_;
|
||||
void* SemHandle_;
|
||||
|
||||
@@ -4,11 +4,11 @@
|
||||
///
|
||||
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
class Memory{
|
||||
public:
|
||||
class Memory {
|
||||
public:
|
||||
static uint64_t FindPattern(const char* module, const char* Pattern[]);
|
||||
static uint32_t GetBeamNGPID(const std::set<uint32_t>& BL);
|
||||
static uint64_t GetModuleBase(const char* Name);
|
||||
|
||||
+58
-47
@@ -5,52 +5,63 @@
|
||||
|
||||
#pragma once
|
||||
namespace Patterns {
|
||||
const char* GetTickCount[2] {
|
||||
"\x48\xff\x25\x00\x00\x00\x00\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\x48\x83\xec\x00\x48\x8d\x4c\x24",
|
||||
"xxx????xxxxxxxxxxxx?xxxx"
|
||||
};
|
||||
const char* open_jit[2] {
|
||||
"\x48\x89\x5c\x24\x00\x48\x89\x74\x24\x00\x57\x48\x83\xec\x00\x48\x8b\x05\x00\x00\x00\x00\x48\x33\xc4\x48\x89\x44\x24\x00\x48\x8b\x71\x00\x48\x8d\x54\x24",
|
||||
"xxxx?xxxx?xxxx?xxx????xxxxxxx?xxx?xxxx"
|
||||
};
|
||||
const char* get_field[2] {
|
||||
"\x48\x89\x5c\x24\x00\x57\x48\x83\xec\x00\x4d\x8b\xd0\x48\x8b\xd9\xe8\x00\x00\x00\x00\x48\x8b\xf8\x49\xc7\xc0\x00\x00\x00\x00\x90\x49\xff\xc0\x43\x80\x3c\x02\x00\x75\x00\x49\x8b\xd2\x48\x8b\xcb\xe8\x00\x00\x00\x00\x48\xb9\x00\x00\x00\x00\x00\x00\x00\x00\x4c\x8d\x44\x24\x00\x48\x0b\xc1\x48\x8b\xd7\x48\x8b\xcb\x48\x89\x44\x24\x00\xe8\x00\x00\x00\x00\x48\x85\xc0",
|
||||
"xxxx?xxxx?xxxxxxx????xxxxxx????xxxxxxxx?x?xxxxxxx????xx????????xxxx?xxxxxxxxxxxxx?x????xxx"
|
||||
};
|
||||
const char* push_fstring[2] {
|
||||
"\x48\x89\x54\x24\x00\x4c\x89\x44\x24\x00\x4c\x89\x4c\x24\x00\x53\x48\x83\xec\x00\x4c\x8b\x41",
|
||||
"xxxx?xxxx?xxxx?xxxx?xxx"
|
||||
};
|
||||
const char* p_call[2] {
|
||||
"\x48\x89\x5c\x24\x00\x48\x89\x74\x24\x00\x57\x48\x83\xec\x00\x48\x8b\x59\x00\x41\x8b\xf0\x4c\x63\xda",
|
||||
"xxxx?xxxx?xxxx?xxx?xxxxxx"
|
||||
};
|
||||
const char* lua_setfield[2] {
|
||||
"\x48\x89\x5c\x24\x00\x57\x48\x83\xec\x00\x4d\x8b\xd0\x48\x8b\xd9\xe8\x00\x00\x00\x00\x48\x8b\xf8\x49\xc7\xc0\x00\x00\x00\x00\x90\x49\xff\xc0\x43\x80\x3c\x02\x00\x75\x00\x49\x8b\xd2\x48\x8b\xcb\xe8\x00\x00\x00\x00\x48\xb9\x00\x00\x00\x00\x00\x00\x00\x00\x4c\x8d\x44\x24\x00\x48\x0b\xc1\x48\x8b\xd7\x48\x8b\xcb\x48\x89\x44\x24\x00\xe8\x00\x00\x00\x00\x48\x8b\x53",
|
||||
"xxxx?xxxx?xxxxxxx????xxxxxx????xxxxxxxx?x?xxxxxxx????xx????????xxxx?xxxxxxxxxxxxx?x????xxx"
|
||||
};
|
||||
const char* lua_createtable[2] {
|
||||
"\x48\x89\x5c\x24\x00\x48\x89\x74\x24\x00\x57\x48\x83\xec\x00\x4c\x8b\x49\x00\x41\x8b\xf8",
|
||||
"xxxx?xxxx?xxxx?xxx?xxx"
|
||||
};
|
||||
const char* lua_settable[2] {
|
||||
"\x40\x53\x48\x83\xec\x00\x48\x8b\xd9\xe8\x00\x00\x00\x00\x4c\x8b\x43\x00\x48\x8b\xd0\x49\x83\xe8\x00\x48\x8b\xcb\xe8\x00\x00\x00\x00\x48\x8b\x53",
|
||||
"xxxxx?xxxx????xxx?xxxxxx?xxxx????xxx"
|
||||
};
|
||||
const char* lua_pushcclosure[2] {
|
||||
"\x48\x89\x5c\x24\x00\x48\x89\x74\x24\x00\x57\x48\x83\xec\x00\x48\x8b\xd9\x49\x63\xf8\x48\x8b\x49\x00\x48\x8b\xf2",
|
||||
"xxxx?xxxx?xxxx?xxxxxxxxx?xxx"
|
||||
};
|
||||
const char* lua_tolstring[2] {
|
||||
"\x48\x89\x5c\x24\x00\x48\x89\x74\x24\x00\x57\x48\x83\xec\x00\x49\x8b\xf8\x8b\xda\x48\x8b\xf1\xe8",
|
||||
"xxxx?xxxx?xxxx?xxxxxxxxx"
|
||||
};
|
||||
const char* GEUpdate[2] {
|
||||
"\x48\x89\x5c\x24\x00\x48\x89\x6c\x24\x00\x56\x57\x41\x56\x48\x83\xec\x00\x4c\x8b\x31\x49\x8b\xf0",
|
||||
"xxxx?xxxx?xxxxxxx?xxxxxx"
|
||||
};
|
||||
const char* lua_settop[2] {
|
||||
const char* GetTickCount[2]{
|
||||
"\x48\xff\x25\x00\x00\x00\x00\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc\x48"
|
||||
"\x83\xec\x00\x48\x8d\x4c\x24",
|
||||
"xxx????xxxxxxxxxxxx?xxxx"};
|
||||
const char* open_jit[2]{
|
||||
"\x48\x89\x5c\x24\x00\x48\x89\x74\x24\x00\x57\x48\x83\xec\x00\x48\x8b"
|
||||
"\x05\x00\x00\x00\x00\x48\x33\xc4\x48\x89\x44\x24\x00\x48\x8b\x71\x00"
|
||||
"\x48\x8d\x54\x24",
|
||||
"xxxx?xxxx?xxxx?xxx????xxxxxxx?xxx?xxxx"};
|
||||
const char* get_field[2]{
|
||||
"\x48\x89\x5c\x24\x00\x57\x48\x83\xec\x00\x4d\x8b\xd0\x48\x8b\xd9\xe8"
|
||||
"\x00\x00\x00\x00\x48\x8b\xf8\x49\xc7\xc0\x00\x00\x00\x00\x90\x49\xff"
|
||||
"\xc0\x43\x80\x3c\x02\x00\x75\x00\x49\x8b\xd2\x48\x8b\xcb\xe8\x00\x00"
|
||||
"\x00\x00\x48\xb9\x00\x00\x00\x00\x00\x00\x00\x00\x4c\x8d\x44\x24\x00"
|
||||
"\x48\x0b\xc1\x48\x8b\xd7\x48\x8b\xcb\x48\x89\x44\x24\x00\xe8\x00\x00"
|
||||
"\x00\x00\x48\x85\xc0",
|
||||
"xxxx?xxxx?xxxxxxx????xxxxxx????xxxxxxxx?x?xxxxxxx????xx????????xxxx?"
|
||||
"xxxxxxxxxxxxx?x????xxx"};
|
||||
const char* push_fstring[2]{
|
||||
"\x48\x89\x54\x24\x00\x4c\x89\x44\x24\x00\x4c\x89\x4c\x24\x00\x53\x48"
|
||||
"\x83\xec\x00\x4c\x8b\x41",
|
||||
"xxxx?xxxx?xxxx?xxxx?xxx"};
|
||||
const char* p_call[2]{
|
||||
"\x48\x89\x5c\x24\x00\x48\x89\x74\x24\x00\x57\x48\x83\xec\x00\x48\x8b"
|
||||
"\x59\x00\x41\x8b\xf0\x4c\x63\xda",
|
||||
"xxxx?xxxx?xxxx?xxx?xxxxxx"};
|
||||
const char* lua_setfield[2]{
|
||||
"\x48\x89\x5c\x24\x00\x57\x48\x83\xec\x00\x4d\x8b\xd0\x48\x8b\xd9\xe8"
|
||||
"\x00\x00\x00\x00\x48\x8b\xf8\x49\xc7\xc0\x00\x00\x00\x00\x90\x49\xff"
|
||||
"\xc0\x43\x80\x3c\x02\x00\x75\x00\x49\x8b\xd2\x48\x8b\xcb\xe8\x00\x00"
|
||||
"\x00\x00\x48\xb9\x00\x00\x00\x00\x00\x00\x00\x00\x4c\x8d\x44\x24\x00"
|
||||
"\x48\x0b\xc1\x48\x8b\xd7\x48\x8b\xcb\x48\x89\x44\x24\x00\xe8\x00\x00"
|
||||
"\x00\x00\x48\x8b\x53",
|
||||
"xxxx?xxxx?xxxxxxx????xxxxxx????xxxxxxxx?x?xxxxxxx????xx????????xxxx?"
|
||||
"xxxxxxxxxxxxx?x????xxx"};
|
||||
const char* lua_createtable[2]{
|
||||
"\x48\x89\x5c\x24\x00\x48\x89\x74\x24\x00\x57\x48\x83\xec\x00\x4c\x8b"
|
||||
"\x49\x00\x41\x8b\xf8",
|
||||
"xxxx?xxxx?xxxx?xxx?xxx"};
|
||||
const char* lua_settable[2]{
|
||||
"\x40\x53\x48\x83\xec\x00\x48\x8b\xd9\xe8\x00\x00\x00\x00\x4c\x8b\x43"
|
||||
"\x00\x48\x8b\xd0\x49\x83\xe8\x00\x48\x8b\xcb\xe8\x00\x00\x00\x00\x48"
|
||||
"\x8b\x53",
|
||||
"xxxxx?xxxx????xxx?xxxxxx?xxxx????xxx"};
|
||||
const char* lua_pushcclosure[2]{
|
||||
"\x48\x89\x5c\x24\x00\x48\x89\x74\x24\x00\x57\x48\x83\xec\x00\x48\x8b"
|
||||
"\xd9\x49\x63\xf8\x48\x8b\x49\x00\x48\x8b\xf2",
|
||||
"xxxx?xxxx?xxxx?xxxxxxxxx?xxx"};
|
||||
const char* lua_tolstring[2]{
|
||||
"\x48\x89\x5c\x24\x00\x48\x89\x74\x24\x00\x57\x48\x83\xec\x00\x49\x8b"
|
||||
"\xf8\x8b\xda\x48\x8b\xf1\xe8",
|
||||
"xxxx?xxxx?xxxx?xxxxxxxxx"};
|
||||
const char* GEUpdate[2]{
|
||||
"\x48\x89\x5c\x24\x00\x48\x89\x6c\x24\x00\x56\x57\x41\x56\x48\x83\xec"
|
||||
"\x00\x4c\x8b\x31\x49\x8b\xf0",
|
||||
"xxxx?xxxx?xxxxxxx?xxxxxx"};
|
||||
const char* lua_settop[2]{
|
||||
"\x4c\x8b\xc1\x85\xd2\x7e\x00\x48\x8b\x41\x00\x48\x8b\x49",
|
||||
"xxxxxx?xxx?xxx"
|
||||
};
|
||||
"xxxxxx?xxx?xxx"};
|
||||
}
|
||||
+15
-13
@@ -12,12 +12,12 @@
|
||||
struct sockaddr_in;
|
||||
class Launcher;
|
||||
class Server {
|
||||
public:
|
||||
public:
|
||||
Server() = delete;
|
||||
explicit Server(Launcher* Instance);
|
||||
~Server();
|
||||
|
||||
public:
|
||||
public:
|
||||
void ServerSend(std::string Data, bool Rel);
|
||||
void Connect(const std::string& Data);
|
||||
const std::string& getModList();
|
||||
@@ -29,11 +29,13 @@ public:
|
||||
int getPing() const;
|
||||
void Close();
|
||||
|
||||
private:
|
||||
std::chrono::time_point<std::chrono::high_resolution_clock> PingStart, PingEnd;
|
||||
std::string MultiDownload(uint64_t DSock, uint64_t Size, const std::string& Name);
|
||||
private:
|
||||
std::chrono::time_point<std::chrono::high_resolution_clock> PingStart,
|
||||
PingEnd;
|
||||
std::string MultiDownload(uint64_t DSock, uint64_t Size,
|
||||
const std::string& Name);
|
||||
void AsyncUpdate(uint64_t& Rcv, uint64_t Size, const std::string& Name);
|
||||
std::atomic<bool> Terminate { false }, ModLoaded { false };
|
||||
std::atomic<bool> Terminate{false}, ModLoaded{false};
|
||||
char* TCPRcvRaw(uint64_t Sock, uint64_t& GRcv, uint64_t Size);
|
||||
std::string GetAddress(const std::string& Data);
|
||||
void InvalidResource(const std::string& File);
|
||||
@@ -56,21 +58,21 @@ private:
|
||||
uint64_t TCPSocket = -1;
|
||||
uint64_t UDPSocket = -1;
|
||||
void WaitForConfirm();
|
||||
std::string UStatus {};
|
||||
std::string MStatus {};
|
||||
std::string ModList {};
|
||||
std::string UStatus{};
|
||||
std::string MStatus{};
|
||||
std::string ModList{};
|
||||
void TCPClientMain();
|
||||
void SyncResources();
|
||||
std::string TCPRcv();
|
||||
uint64_t InitDSock();
|
||||
std::string Auth();
|
||||
std::string IP {};
|
||||
std::string IP{};
|
||||
void UDPClient();
|
||||
void PingLoop();
|
||||
int ClientID { 0 };
|
||||
int ClientID{0};
|
||||
void UDPMain();
|
||||
void UDPRcv();
|
||||
void Abort();
|
||||
int Port { 0 };
|
||||
int Ping { 0 };
|
||||
int Port{0};
|
||||
int Ping{0};
|
||||
};
|
||||
|
||||
+9
-13
@@ -7,13 +7,12 @@
|
||||
#include <queue>
|
||||
#include <semaphore>
|
||||
|
||||
template <class T, size_t Size>
|
||||
template<class T, size_t Size>
|
||||
class atomic_queue {
|
||||
public:
|
||||
public:
|
||||
bool try_pop(T& val) {
|
||||
lock_guard guard(semaphore);
|
||||
if (queue.empty())
|
||||
return false;
|
||||
if (queue.empty()) return false;
|
||||
val = queue.front();
|
||||
queue.pop();
|
||||
full.release();
|
||||
@@ -36,26 +35,23 @@ public:
|
||||
return queue.empty();
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
void check_full() {
|
||||
if (size() >= Size) {
|
||||
full.acquire();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
struct lock_guard {
|
||||
explicit lock_guard(std::binary_semaphore& lock)
|
||||
: lock(lock) {
|
||||
explicit lock_guard(std::binary_semaphore& lock) : lock(lock) {
|
||||
lock.acquire();
|
||||
}
|
||||
~lock_guard() {
|
||||
lock.release();
|
||||
}
|
||||
~lock_guard() { lock.release(); }
|
||||
|
||||
private:
|
||||
std::binary_semaphore& lock;
|
||||
};
|
||||
std::binary_semaphore semaphore { 1 }, full { 0 };
|
||||
std::queue<T> queue {};
|
||||
std::binary_semaphore semaphore{1}, full{0};
|
||||
std::queue<T> queue{};
|
||||
};
|
||||
|
||||
+5
-11
@@ -3,9 +3,9 @@
|
||||
/// Copyright (c) 2021-present Anonymous275 read the LICENSE file for more info.
|
||||
///
|
||||
|
||||
#include <tomlplusplus/toml.hpp>
|
||||
#include "Launcher.h"
|
||||
#include "Logger.h"
|
||||
#include <tomlplusplus/toml.hpp>
|
||||
|
||||
void Launcher::LoadConfig() {
|
||||
if (fs::exists("Launcher.toml")) {
|
||||
@@ -14,24 +14,18 @@ void Launcher::LoadConfig() {
|
||||
auto build = config["Build"];
|
||||
if (ui.is_boolean()) {
|
||||
EnableUI = ui.as_boolean()->get();
|
||||
} else
|
||||
LOG(ERROR) << "Failed to get 'UI' boolean from config";
|
||||
} else LOG(ERROR) << "Failed to get 'UI' boolean from config";
|
||||
|
||||
// Default -1 / Release 1 / EA 2 / Dev 3 / Custom 3
|
||||
if (build.is_string()) {
|
||||
TargetBuild = build.as_string()->get();
|
||||
for (char& c : TargetBuild)
|
||||
c = char(tolower(c));
|
||||
} else
|
||||
LOG(ERROR) << "Failed to get 'Build' string from config";
|
||||
for (char& c : TargetBuild) c = char(tolower(c));
|
||||
} else LOG(ERROR) << "Failed to get 'Build' string from config";
|
||||
|
||||
} else {
|
||||
std::ofstream tml("Launcher.toml");
|
||||
if (tml.is_open()) {
|
||||
tml <<
|
||||
R"(UI = true
|
||||
Build = "Default"
|
||||
)";
|
||||
tml << "UI = true\n Build = \"Default\"";
|
||||
tml.close();
|
||||
} else {
|
||||
LOG(FATAL) << "Failed to write config on disk!";
|
||||
|
||||
+6
-6
@@ -3,13 +3,13 @@
|
||||
/// Copyright (c) 2021-present Anonymous275 read the LICENSE file for more info.
|
||||
///
|
||||
#ifndef DEBUG
|
||||
#include <discord_rpc.h>
|
||||
#include <ctime>
|
||||
#include "Launcher.h"
|
||||
#include "Logger.h"
|
||||
#include <ctime>
|
||||
#include <discord_rpc.h>
|
||||
|
||||
void handleReady(const DiscordUser* u) { }
|
||||
void handleDisconnected(int errcode, const char* message) { }
|
||||
void handleReady(const DiscordUser* u) {}
|
||||
void handleDisconnected(int errcode, const char* message) {}
|
||||
void handleError(int errcode, const char* message) {
|
||||
LOG(ERROR) << "Discord error: " << message;
|
||||
}
|
||||
@@ -58,6 +58,6 @@ void Launcher::setDiscordMessage(const std::string& message) {
|
||||
void Launcher::RunDiscordRPC() {
|
||||
DiscordRPC = std::thread(&Launcher::RichPresence, this);
|
||||
}
|
||||
void Launcher::RichPresence() {};
|
||||
void Launcher::UpdatePresence() {};
|
||||
void Launcher::RichPresence(){};
|
||||
void Launcher::UpdatePresence(){};
|
||||
#endif
|
||||
+13
-18
@@ -11,8 +11,7 @@
|
||||
|
||||
void Launcher::HandleIPC(const std::string& Data) {
|
||||
char Code = Data.at(0), SubCode = 0;
|
||||
if (Data.length() > 1)
|
||||
SubCode = Data.at(1);
|
||||
if (Data.length() > 1) SubCode = Data.at(1);
|
||||
switch (Code) {
|
||||
case 'A':
|
||||
ServerHandler.StartUDP();
|
||||
@@ -25,20 +24,18 @@ void Launcher::HandleIPC(const std::string& Data) {
|
||||
case 'C':
|
||||
ServerHandler.Close();
|
||||
ServerHandler.Connect(Data);
|
||||
while (ServerHandler.getModList().empty() && !ServerHandler.Terminated()) {
|
||||
while (ServerHandler.getModList().empty() &&
|
||||
!ServerHandler.Terminated()) {
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
}
|
||||
if (ServerHandler.getModList() == "-")
|
||||
SendIPC("L");
|
||||
else
|
||||
SendIPC("L" + ServerHandler.getModList());
|
||||
if (ServerHandler.getModList() == "-") SendIPC("L");
|
||||
else SendIPC("L" + ServerHandler.getModList());
|
||||
break;
|
||||
case 'U':
|
||||
SendIPC("Ul" + ServerHandler.getUIStatus());
|
||||
if (ServerHandler.getPing() > 800) {
|
||||
SendIPC("Up-2");
|
||||
} else
|
||||
SendIPC("Up" + std::to_string(ServerHandler.getPing()));
|
||||
} else SendIPC("Up" + std::to_string(ServerHandler.getPing()));
|
||||
break;
|
||||
case 'M':
|
||||
SendIPC(ServerHandler.getMap());
|
||||
@@ -47,8 +44,7 @@ void Launcher::HandleIPC(const std::string& Data) {
|
||||
if (SubCode == 'S') {
|
||||
ServerHandler.Close();
|
||||
}
|
||||
if (SubCode == 'G')
|
||||
exit(2);
|
||||
if (SubCode == 'G') exit(2);
|
||||
break;
|
||||
case 'R': // will send mod name
|
||||
ServerHandler.setModLoaded();
|
||||
@@ -69,18 +65,17 @@ void Launcher::HandleIPC(const std::string& Data) {
|
||||
}
|
||||
|
||||
void Server::ServerParser(const std::string& Data) {
|
||||
if (Data.empty())
|
||||
return;
|
||||
if (Data.empty()) return;
|
||||
char Code = Data.at(0), SubCode = 0;
|
||||
if (Data.length() > 1)
|
||||
SubCode = Data.at(1);
|
||||
if (Data.length() > 1) SubCode = Data.at(1);
|
||||
switch (Code) {
|
||||
case 'p':
|
||||
PingEnd = std::chrono::high_resolution_clock::now();
|
||||
if (PingStart > PingEnd)
|
||||
Ping = 0;
|
||||
if (PingStart > PingEnd) Ping = 0;
|
||||
else
|
||||
Ping = int(std::chrono::duration_cast<std::chrono::milliseconds>(PingEnd - PingStart).count());
|
||||
Ping = int(std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
PingEnd - PingStart)
|
||||
.count());
|
||||
return;
|
||||
case 'M':
|
||||
MStatus = Data;
|
||||
|
||||
+43
-29
@@ -5,24 +5,25 @@
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include "Launcher.h"
|
||||
#include <ShlObj.h>
|
||||
#include <comutil.h>
|
||||
#include <shellapi.h>
|
||||
#include <windows.h>
|
||||
#include <csignal>
|
||||
#include <mutex>
|
||||
#include "HttpAPI.h"
|
||||
#include "Logger.h"
|
||||
#include "Memory/Memory.h"
|
||||
#include <ShlObj.h>
|
||||
#include <comutil.h>
|
||||
#include <csignal>
|
||||
#include <mutex>
|
||||
#include <shellapi.h>
|
||||
#include <windows.h>
|
||||
|
||||
LONG WINAPI CrashHandler(EXCEPTION_POINTERS* p) {
|
||||
LOG(ERROR) << "CAUGHT EXCEPTION! Code 0x" << std::hex << std::uppercase << p->ExceptionRecord->ExceptionCode;
|
||||
LOG(ERROR) << "CAUGHT EXCEPTION! Code 0x" << std::hex << std::uppercase
|
||||
<< p->ExceptionRecord->ExceptionCode;
|
||||
return EXCEPTION_EXECUTE_HANDLER;
|
||||
}
|
||||
|
||||
Launcher::Launcher(int argc, char* argv[])
|
||||
: CurrentPath(std::filesystem::path(argv[0]))
|
||||
, DiscordMessage("Just launched") {
|
||||
Launcher::Launcher(int argc, char* argv[]) :
|
||||
CurrentPath(std::filesystem::path(argv[0])),
|
||||
DiscordMessage("Just launched") {
|
||||
Launcher::StaticAbort(this);
|
||||
DiscordTime = std::time(nullptr);
|
||||
Log::Init();
|
||||
@@ -89,22 +90,30 @@ void Launcher::WindowsInit() {
|
||||
void Launcher::LaunchGame() {
|
||||
VersionParser GameVersion(BeamVersion);
|
||||
if (GameVersion.data[1] > SupportedVersion.data[1]) {
|
||||
LOG(FATAL) << "BeamNG V" << BeamVersion << " not yet supported, please wait until we update BeamMP!";
|
||||
LOG(FATAL) << "BeamNG V" << BeamVersion
|
||||
<< " not yet supported, please wait until we update BeamMP!";
|
||||
throw ShutdownException("Fatal Error");
|
||||
} else if (GameVersion.data[1] < SupportedVersion.data[1]) {
|
||||
LOG(FATAL) << "BeamNG V" << BeamVersion << " not supported, please update and launch the new update!";
|
||||
LOG(FATAL) << "BeamNG V" << BeamVersion
|
||||
<< " not supported, please update and launch the new update!";
|
||||
throw ShutdownException("Fatal Error");
|
||||
} else if (GameVersion > SupportedVersion) {
|
||||
LOG(WARNING) << "BeamNG V" << BeamVersion << " is slightly newer than recommended, this might cause issues!";
|
||||
LOG(WARNING)
|
||||
<< "BeamNG V" << BeamVersion
|
||||
<< " is slightly newer than recommended, this might cause issues!";
|
||||
} else if (GameVersion < SupportedVersion) {
|
||||
LOG(WARNING) << "BeamNG V" << BeamVersion << " is slightly older than recommended, this might cause issues!";
|
||||
LOG(WARNING)
|
||||
<< "BeamNG V" << BeamVersion
|
||||
<< " is slightly older than recommended, this might cause issues!";
|
||||
}
|
||||
if (Memory::GetBeamNGPID({}) == 0) {
|
||||
LOG(INFO) << "Launching BeamNG from steam";
|
||||
ShellExecuteA(nullptr, nullptr, "steam://rungameid/284160", nullptr, nullptr, SW_SHOWNORMAL);
|
||||
ShellExecuteA(nullptr, nullptr, "steam://rungameid/284160", nullptr,
|
||||
nullptr, SW_SHOWNORMAL);
|
||||
// ShowWindow(GetConsoleWindow(), HIDE_WINDOW);
|
||||
}
|
||||
LOG(INFO) << "Waiting for a game process, please start BeamNG manually in case of steam issues";
|
||||
LOG(INFO) << "Waiting for a game process, please start BeamNG manually in "
|
||||
"case of steam issues";
|
||||
}
|
||||
|
||||
void Launcher::WaitForGame() {
|
||||
@@ -118,8 +127,7 @@ void Launcher::WaitForGame() {
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
} while (GamePID == 0 && !Shutdown.load());
|
||||
if (Shutdown.load())
|
||||
return;
|
||||
if (Shutdown.load()) return;
|
||||
|
||||
if (GamePID == 0) {
|
||||
LOG(FATAL) << "Game process not found! aborting";
|
||||
@@ -159,10 +167,8 @@ void Launcher::ListenIPC() {
|
||||
void Launcher::SendIPC(const std::string& Data, bool core) {
|
||||
static std::mutex Lock;
|
||||
std::scoped_lock Guard(Lock);
|
||||
if (core)
|
||||
IPCToGame->send("C" + Data);
|
||||
else
|
||||
IPCToGame->send("G" + Data);
|
||||
if (core) IPCToGame->send("C" + Data);
|
||||
else IPCToGame->send("G" + Data);
|
||||
if (IPCToGame->send_timed_out()) {
|
||||
LOG(WARNING) << "Timed out while sending \"" << Data << "\"";
|
||||
}
|
||||
@@ -171,15 +177,17 @@ void Launcher::SendIPC(const std::string& Data, bool core) {
|
||||
std::string QueryValue(HKEY& hKey, const char* Name) {
|
||||
DWORD keySize;
|
||||
BYTE buffer[16384];
|
||||
if (RegQueryValueExA(hKey, Name, nullptr, nullptr, buffer, &keySize) == ERROR_SUCCESS) {
|
||||
return { (char*)buffer, keySize - 1 };
|
||||
if (RegQueryValueExA(hKey, Name, nullptr, nullptr, buffer, &keySize) ==
|
||||
ERROR_SUCCESS) {
|
||||
return {(char*)buffer, keySize - 1};
|
||||
}
|
||||
return {};
|
||||
}
|
||||
std::string Launcher::GetLocalAppdata() {
|
||||
PWSTR folderPath = nullptr;
|
||||
|
||||
HRESULT hr = SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, nullptr, &folderPath);
|
||||
HRESULT hr =
|
||||
SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, nullptr, &folderPath);
|
||||
|
||||
if (!SUCCEEDED(hr)) {
|
||||
LOG(FATAL) << "Failed to get path of localAppData";
|
||||
@@ -200,7 +208,9 @@ std::string Launcher::GetLocalAppdata() {
|
||||
}
|
||||
void Launcher::QueryRegistry() {
|
||||
HKEY BeamNG;
|
||||
LONG RegRes = RegOpenKeyExA(HKEY_CURRENT_USER, R"(Software\BeamNG\BeamNG.drive)", 0, KEY_READ, &BeamNG);
|
||||
LONG RegRes =
|
||||
RegOpenKeyExA(HKEY_CURRENT_USER, R"(Software\BeamNG\BeamNG.drive)", 0,
|
||||
KEY_READ, &BeamNG);
|
||||
if (RegRes == ERROR_SUCCESS) {
|
||||
BeamRoot = QueryValue(BeamNG, "rootpath");
|
||||
BeamVersion = QueryValue(BeamNG, "version");
|
||||
@@ -218,19 +228,23 @@ void Launcher::QueryRegistry() {
|
||||
if (!BeamRoot.empty() && !BeamVersion.empty() && !BeamUserPath.empty())
|
||||
return;
|
||||
}
|
||||
LOG(FATAL) << "Please launch the game at least once, failed to read registry key Software\\BeamNG\\BeamNG.drive";
|
||||
LOG(FATAL)
|
||||
<< "Please launch the game at least once, failed to read registry "
|
||||
"key Software\\BeamNG\\BeamNG.drive";
|
||||
throw ShutdownException("Fatal Error");
|
||||
}
|
||||
|
||||
void Launcher::AdminRelaunch() {
|
||||
system("cls");
|
||||
ShellExecuteA(nullptr, "runas", CurrentPath.string().c_str(), nullptr, nullptr, SW_SHOWNORMAL);
|
||||
ShellExecuteA(nullptr, "runas", CurrentPath.string().c_str(), nullptr,
|
||||
nullptr, SW_SHOWNORMAL);
|
||||
ShowWindow(GetConsoleWindow(), 0);
|
||||
throw ShutdownException("Relaunching");
|
||||
}
|
||||
|
||||
void Launcher::Relaunch() {
|
||||
ShellExecuteA(nullptr, "open", CurrentPath.string().c_str(), nullptr, nullptr, SW_SHOWNORMAL);
|
||||
ShellExecuteA(nullptr, "open", CurrentPath.string().c_str(), nullptr,
|
||||
nullptr, SW_SHOWNORMAL);
|
||||
ShowWindow(GetConsoleWindow(), 0);
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
throw ShutdownException("Relaunching");
|
||||
|
||||
+4
-2
@@ -9,8 +9,10 @@ using namespace el;
|
||||
void Log::Init() {
|
||||
Configurations Conf;
|
||||
Conf.setToDefault();
|
||||
std::string DFormat("%datetime{[%d/%M/%y %H:%m:%s]} %fbase:%line [%level] %msg");
|
||||
Conf.setGlobally(ConfigurationType::Format, "%datetime{[%d/%M/%y %H:%m:%s]} [%level] %msg");
|
||||
std::string DFormat(
|
||||
"%datetime{[%d/%M/%y %H:%m:%s]} %fbase:%line [%level] %msg");
|
||||
Conf.setGlobally(ConfigurationType::Format,
|
||||
"%datetime{[%d/%M/%y %H:%m:%s]} [%level] %msg");
|
||||
Conf.setGlobally(ConfigurationType::LogFlushThreshold, "2");
|
||||
Conf.set(Level::Verbose, ConfigurationType::Format, DFormat);
|
||||
Conf.set(Level::Debug, ConfigurationType::Format, DFormat);
|
||||
|
||||
@@ -26,7 +26,8 @@ void BeamNG::EntryPoint() {
|
||||
GELua::FindAddresses();
|
||||
/*GameBaseAddr = Memory::GetModuleBase(GameModule);
|
||||
DllBaseAddr = Memory::GetModuleBase(DllModule);*/
|
||||
OpenJITDetour = std::make_unique<Hook<def::lua_open_jit>>(GELua::lua_open_jit, lua_open_jit_D);
|
||||
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);
|
||||
@@ -37,7 +38,8 @@ int Core(lua_State* L) {
|
||||
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);
|
||||
}
|
||||
@@ -48,7 +50,8 @@ int Game(lua_State* L) {
|
||||
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);
|
||||
}
|
||||
@@ -86,8 +89,7 @@ void BeamNG::IPCListener() {
|
||||
TimeOuts = 0;
|
||||
Queue->push(IPCFromLauncher->msg());
|
||||
IPCFromLauncher->confirm_receive();
|
||||
} else
|
||||
TimeOuts++;
|
||||
} else TimeOuts++;
|
||||
}
|
||||
Memory::Print("IPC System shutting down");
|
||||
}
|
||||
|
||||
+49
-25
@@ -13,34 +13,58 @@ 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() {
|
||||
GELua::State = nullptr;
|
||||
auto Base = Memory::GetModuleBase(GameModule);
|
||||
GetTickCount = reinterpret_cast<def::GetTickCount>(Memory::FindPattern(GameModule, Patterns::GetTickCount));
|
||||
Memory::Print("GetTickCount -> " + GetHex(reinterpret_cast<uint64_t>(GetTickCount) - Base));
|
||||
lua_open_jit = reinterpret_cast<def::lua_open_jit>(Memory::FindPattern(GameModule, Patterns::open_jit));
|
||||
Memory::Print("lua_open_jit -> " + GetHex(reinterpret_cast<uint64_t>(lua_open_jit) - Base));
|
||||
lua_push_fstring = reinterpret_cast<def::lua_push_fstring>(Memory::FindPattern(GameModule, Patterns::push_fstring));
|
||||
Memory::Print("lua_push_fstring -> " + GetHex(reinterpret_cast<uint64_t>(lua_push_fstring) - Base));
|
||||
lua_get_field = reinterpret_cast<def::lua_get_field>(Memory::FindPattern(GameModule, Patterns::get_field));
|
||||
Memory::Print("lua_get_field -> " + GetHex(reinterpret_cast<uint64_t>(lua_get_field) - Base));
|
||||
lua_p_call = reinterpret_cast<def::lua_p_call>(Memory::FindPattern(GameModule, Patterns::p_call));
|
||||
Memory::Print("lua_p_call -> " + GetHex(reinterpret_cast<uint64_t>(lua_p_call) - Base));
|
||||
lua_createtable = reinterpret_cast<def::lua_createtable>(Memory::FindPattern(GameModule, Patterns::lua_createtable));
|
||||
Memory::Print("lua_createtable -> " + GetHex(reinterpret_cast<uint64_t>(lua_createtable) - Base));
|
||||
lua_pushcclosure = reinterpret_cast<def::lua_pushcclosure>(Memory::FindPattern(GameModule, Patterns::lua_pushcclosure));
|
||||
Memory::Print("lua_pushcclosure -> " + GetHex(reinterpret_cast<uint64_t>(lua_pushcclosure) - Base));
|
||||
lua_setfield = reinterpret_cast<def::lua_setfield>(Memory::FindPattern(GameModule, Patterns::lua_setfield));
|
||||
Memory::Print("lua_setfield -> " + GetHex(reinterpret_cast<uint64_t>(lua_setfield) - Base));
|
||||
lua_settable = reinterpret_cast<def::lua_settable>(Memory::FindPattern(GameModule, Patterns::lua_settable));
|
||||
Memory::Print("lua_settable -> " + GetHex(reinterpret_cast<uint64_t>(lua_settable) - Base));
|
||||
lua_tolstring = reinterpret_cast<def::lua_tolstring>(Memory::FindPattern(GameModule, Patterns::lua_tolstring));
|
||||
Memory::Print("lua_tolstring -> " + GetHex(reinterpret_cast<uint64_t>(lua_tolstring) - Base));
|
||||
GEUpdate = reinterpret_cast<def::GEUpdate>(Memory::FindPattern(GameModule, Patterns::GEUpdate));
|
||||
Memory::Print("GEUpdate -> " + GetHex(reinterpret_cast<uint64_t>(GEUpdate) - Base));
|
||||
lua_settop = reinterpret_cast<def::lua_settop>(Memory::FindPattern(GameModule, Patterns::lua_settop));
|
||||
Memory::Print("lua_settop -> " + GetHex(reinterpret_cast<uint64_t>(lua_settop) - Base));
|
||||
GetTickCount = reinterpret_cast<def::GetTickCount>(
|
||||
Memory::FindPattern(GameModule, Patterns::GetTickCount));
|
||||
Memory::Print("GetTickCount -> " +
|
||||
GetHex(reinterpret_cast<uint64_t>(GetTickCount) - Base));
|
||||
lua_open_jit = reinterpret_cast<def::lua_open_jit>(
|
||||
Memory::FindPattern(GameModule, Patterns::open_jit));
|
||||
Memory::Print("lua_open_jit -> " +
|
||||
GetHex(reinterpret_cast<uint64_t>(lua_open_jit) - Base));
|
||||
lua_push_fstring = reinterpret_cast<def::lua_push_fstring>(
|
||||
Memory::FindPattern(GameModule, Patterns::push_fstring));
|
||||
Memory::Print("lua_push_fstring -> " +
|
||||
GetHex(reinterpret_cast<uint64_t>(lua_push_fstring) - Base));
|
||||
lua_get_field = reinterpret_cast<def::lua_get_field>(
|
||||
Memory::FindPattern(GameModule, Patterns::get_field));
|
||||
Memory::Print("lua_get_field -> " +
|
||||
GetHex(reinterpret_cast<uint64_t>(lua_get_field) - Base));
|
||||
lua_p_call = reinterpret_cast<def::lua_p_call>(
|
||||
Memory::FindPattern(GameModule, Patterns::p_call));
|
||||
Memory::Print("lua_p_call -> " +
|
||||
GetHex(reinterpret_cast<uint64_t>(lua_p_call) - Base));
|
||||
lua_createtable = reinterpret_cast<def::lua_createtable>(
|
||||
Memory::FindPattern(GameModule, Patterns::lua_createtable));
|
||||
Memory::Print("lua_createtable -> " +
|
||||
GetHex(reinterpret_cast<uint64_t>(lua_createtable) - Base));
|
||||
lua_pushcclosure = reinterpret_cast<def::lua_pushcclosure>(
|
||||
Memory::FindPattern(GameModule, Patterns::lua_pushcclosure));
|
||||
Memory::Print("lua_pushcclosure -> " +
|
||||
GetHex(reinterpret_cast<uint64_t>(lua_pushcclosure) - Base));
|
||||
lua_setfield = reinterpret_cast<def::lua_setfield>(
|
||||
Memory::FindPattern(GameModule, Patterns::lua_setfield));
|
||||
Memory::Print("lua_setfield -> " +
|
||||
GetHex(reinterpret_cast<uint64_t>(lua_setfield) - Base));
|
||||
lua_settable = reinterpret_cast<def::lua_settable>(
|
||||
Memory::FindPattern(GameModule, Patterns::lua_settable));
|
||||
Memory::Print("lua_settable -> " +
|
||||
GetHex(reinterpret_cast<uint64_t>(lua_settable) - Base));
|
||||
lua_tolstring = reinterpret_cast<def::lua_tolstring>(
|
||||
Memory::FindPattern(GameModule, Patterns::lua_tolstring));
|
||||
Memory::Print("lua_tolstring -> " +
|
||||
GetHex(reinterpret_cast<uint64_t>(lua_tolstring) - Base));
|
||||
GEUpdate = reinterpret_cast<def::GEUpdate>(
|
||||
Memory::FindPattern(GameModule, Patterns::GEUpdate));
|
||||
Memory::Print("GEUpdate -> " +
|
||||
GetHex(reinterpret_cast<uint64_t>(GEUpdate) - Base));
|
||||
lua_settop = reinterpret_cast<def::lua_settop>(
|
||||
Memory::FindPattern(GameModule, Patterns::lua_settop));
|
||||
Memory::Print("lua_settop -> " +
|
||||
GetHex(reinterpret_cast<uint64_t>(lua_settop) - Base));
|
||||
}
|
||||
|
||||
+11
-9
@@ -7,23 +7,25 @@
|
||||
#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());
|
||||
SemHandle_ =
|
||||
OpenSemaphoreA(SYNCHRONIZE | SEMAPHORE_MODIFY_STATE, FALSE, Sem.c_str());
|
||||
if (SemHandle_ == nullptr) {
|
||||
SemHandle_ = CreateSemaphoreA(nullptr, 0, 1, Sem.c_str());
|
||||
}
|
||||
SemConfHandle_ = OpenSemaphoreA(SYNCHRONIZE | SEMAPHORE_MODIFY_STATE, FALSE, SemConf.c_str());
|
||||
SemConfHandle_ = OpenSemaphoreA(SYNCHRONIZE | SEMAPHORE_MODIFY_STATE, FALSE,
|
||||
SemConf.c_str());
|
||||
if (SemConfHandle_ == nullptr) {
|
||||
SemConfHandle_ = CreateSemaphoreA(nullptr, 0, 1, SemConf.c_str());
|
||||
}
|
||||
MemoryHandle_ = OpenFileMappingA(FILE_MAP_ALL_ACCESS, FALSE, Mem.c_str());
|
||||
if (MemoryHandle_ == nullptr) {
|
||||
MemoryHandle_ = CreateFileMappingA(INVALID_HANDLE_VALUE, nullptr, PAGE_READWRITE, 0, DWORD(Size), Mem.c_str());
|
||||
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);
|
||||
}
|
||||
@@ -83,7 +85,7 @@ 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);
|
||||
|
||||
+39
-19
@@ -6,10 +6,10 @@
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#undef UNICODE
|
||||
#include "Memory/Memory.h"
|
||||
#include "Memory/BeamNG.h"
|
||||
#include <psapi.h>
|
||||
#include <string>
|
||||
#include <tlhelp32.h>
|
||||
#include <string>
|
||||
#include "Memory/BeamNG.h"
|
||||
|
||||
uint32_t Memory::GetBeamNGPID(const std::set<uint32_t>& BL) {
|
||||
SetLastError(0);
|
||||
@@ -19,9 +19,9 @@ uint32_t Memory::GetBeamNGPID(const std::set<uint32_t>& BL) {
|
||||
|
||||
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 (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));
|
||||
@@ -31,8 +31,7 @@ uint32_t Memory::GetBeamNGPID(const std::set<uint32_t>& BL) {
|
||||
CloseHandle(Snapshot);
|
||||
}
|
||||
|
||||
if (GetLastError() != 0)
|
||||
return 0;
|
||||
if (GetLastError() != 0) return 0;
|
||||
return pe32.th32ProcessID;
|
||||
}
|
||||
|
||||
@@ -45,15 +44,17 @@ uint32_t Memory::GetPID() {
|
||||
}
|
||||
|
||||
uint64_t Memory::FindPattern(const char* module, const char* Pattern[]) {
|
||||
MODULEINFO mInfo { nullptr };
|
||||
GetModuleInformation(GetCurrentProcess(), GetModuleHandleA(module), &mInfo, sizeof(MODULEINFO));
|
||||
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++) {
|
||||
bool found = true;
|
||||
for (auto j = 0; j < len && found; j++) {
|
||||
found &= Pattern[1][j] == '?' || Pattern[0][j] == *(char*)(base + i + j);
|
||||
found &=
|
||||
Pattern[1][j] == '?' || Pattern[0][j] == *(char*)(base + i + j);
|
||||
}
|
||||
if (found) {
|
||||
return base + i;
|
||||
@@ -86,31 +87,50 @@ typedef struct BASE_RELOCATION_ENTRY {
|
||||
void Memory::Inject(uint32_t PID) {
|
||||
PVOID imageBase = GetModuleHandle(nullptr);
|
||||
auto dosHeader = (PIMAGE_DOS_HEADER)imageBase;
|
||||
auto ntHeader = (PIMAGE_NT_HEADERS)((DWORD_PTR)imageBase + dosHeader->e_lfanew);
|
||||
auto ntHeader =
|
||||
(PIMAGE_NT_HEADERS)((DWORD_PTR)imageBase + dosHeader->e_lfanew);
|
||||
|
||||
PVOID localImage = VirtualAlloc(nullptr, ntHeader->OptionalHeader.SizeOfImage, MEM_COMMIT, PAGE_READWRITE);
|
||||
PVOID localImage =
|
||||
VirtualAlloc(nullptr, ntHeader->OptionalHeader.SizeOfImage, MEM_COMMIT,
|
||||
PAGE_READWRITE);
|
||||
memcpy(localImage, imageBase, ntHeader->OptionalHeader.SizeOfImage);
|
||||
|
||||
HANDLE targetProcess = OpenProcess(MAXIMUM_ALLOWED, FALSE, PID);
|
||||
PVOID targetImage = VirtualAllocEx(targetProcess, nullptr, ntHeader->OptionalHeader.SizeOfImage, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
|
||||
PVOID targetImage = VirtualAllocEx(targetProcess, nullptr,
|
||||
ntHeader->OptionalHeader.SizeOfImage,
|
||||
MEM_COMMIT, PAGE_EXECUTE_READWRITE);
|
||||
|
||||
DWORD_PTR deltaImageBase = DWORD_PTR(targetImage) - DWORD_PTR(imageBase);
|
||||
|
||||
auto relocationTable = (PIMAGE_BASE_RELOCATION)((DWORD_PTR)localImage + ntHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress);
|
||||
auto relocationTable =
|
||||
(PIMAGE_BASE_RELOCATION)((DWORD_PTR)localImage +
|
||||
ntHeader->OptionalHeader
|
||||
.DataDirectory
|
||||
[IMAGE_DIRECTORY_ENTRY_BASERELOC]
|
||||
.VirtualAddress);
|
||||
PDWORD_PTR patchedAddress;
|
||||
while (relocationTable->SizeOfBlock > 0) {
|
||||
DWORD relocationEntriesCount = (relocationTable->SizeOfBlock - sizeof(IMAGE_BASE_RELOCATION)) / sizeof(USHORT);
|
||||
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) {
|
||||
patchedAddress = PDWORD_PTR(DWORD_PTR(localImage) + relocationTable->VirtualAddress + relocationRVA[i].Offset);
|
||||
patchedAddress = PDWORD_PTR(DWORD_PTR(localImage) +
|
||||
relocationTable->VirtualAddress +
|
||||
relocationRVA[i].Offset);
|
||||
*patchedAddress += deltaImageBase;
|
||||
}
|
||||
}
|
||||
relocationTable = PIMAGE_BASE_RELOCATION(DWORD_PTR(relocationTable) + relocationTable->SizeOfBlock);
|
||||
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);
|
||||
WriteProcessMemory(targetProcess, targetImage, localImage,
|
||||
ntHeader->OptionalHeader.SizeOfImage, nullptr);
|
||||
CreateRemoteThread(
|
||||
targetProcess, nullptr, 0,
|
||||
(LPTHREAD_START_ROUTINE)((DWORD_PTR)EntryPoint + deltaImageBase),
|
||||
nullptr, 0, nullptr);
|
||||
CloseHandle(targetProcess);
|
||||
}
|
||||
|
||||
|
||||
+15
-18
@@ -4,13 +4,13 @@
|
||||
///
|
||||
#define CPPHTTPLIB_OPENSSL_SUPPORT
|
||||
#include "HttpAPI.h"
|
||||
#include "Launcher.h"
|
||||
#include "Logger.h"
|
||||
#include <cmath>
|
||||
#include <cpp-httplib/httplib.h>
|
||||
#include <cmath>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <mutex>
|
||||
#include "Launcher.h"
|
||||
#include "Logger.h"
|
||||
|
||||
bool HTTP::isDownload = false;
|
||||
std::atomic<httplib::Client*> CliRef = nullptr;
|
||||
@@ -29,8 +29,7 @@ std::string HTTP::Get(const std::string& IP) {
|
||||
if (res.error() == httplib::Error::Success) {
|
||||
if (res->status == 200) {
|
||||
Ret = res->body;
|
||||
} else
|
||||
LOG(ERROR) << res->reason;
|
||||
} else LOG(ERROR) << res->reason;
|
||||
|
||||
} else {
|
||||
if (isDownload) {
|
||||
@@ -54,7 +53,8 @@ std::string HTTP::Post(const std::string& IP, const std::string& Fields) {
|
||||
std::string Ret;
|
||||
|
||||
if (!Fields.empty()) {
|
||||
httplib::Result res = cli.Post(IP.substr(pos).c_str(), Fields, "application/json");
|
||||
httplib::Result res =
|
||||
cli.Post(IP.substr(pos).c_str(), Fields, "application/json");
|
||||
|
||||
if (res.error() == httplib::Error::Success) {
|
||||
if (res->status != 200) {
|
||||
@@ -62,7 +62,8 @@ std::string HTTP::Post(const std::string& IP, const std::string& Fields) {
|
||||
}
|
||||
Ret = res->body;
|
||||
} else {
|
||||
LOG(ERROR) << "HTTP Post failed on " << httplib::to_string(res.error());
|
||||
LOG(ERROR) << "HTTP Post failed on "
|
||||
<< httplib::to_string(res.error());
|
||||
}
|
||||
} else {
|
||||
httplib::Result res = cli.Post(IP.substr(pos).c_str());
|
||||
@@ -72,14 +73,13 @@ std::string HTTP::Post(const std::string& IP, const std::string& Fields) {
|
||||
}
|
||||
Ret = res->body;
|
||||
} else {
|
||||
LOG(ERROR) << "HTTP Post failed on " << httplib::to_string(res.error());
|
||||
LOG(ERROR) << "HTTP Post failed on "
|
||||
<< httplib::to_string(res.error());
|
||||
}
|
||||
}
|
||||
CliRef.store(nullptr);
|
||||
if (Ret.empty())
|
||||
return "-1";
|
||||
else
|
||||
return Ret;
|
||||
if (Ret.empty()) return "-1";
|
||||
else return Ret;
|
||||
}
|
||||
|
||||
bool HTTP::ProgressBar(size_t c, size_t t) {
|
||||
@@ -91,10 +91,8 @@ bool HTTP::ProgressBar(size_t c, size_t t) {
|
||||
std::cout << round(double(c) / double(t) * 100);
|
||||
std::cout << "% ] [";
|
||||
int i;
|
||||
for (i = 0; i <= progress_bar_adv; i++)
|
||||
std::cout << "#";
|
||||
for (i = 0; i < 25 - progress_bar_adv; i++)
|
||||
std::cout << ".";
|
||||
for (i = 0; i <= progress_bar_adv; i++) std::cout << "#";
|
||||
for (i = 0; i < 25 - progress_bar_adv; i++) std::cout << ".";
|
||||
std::cout << "]";
|
||||
}
|
||||
if (Launcher::Terminated()) {
|
||||
@@ -114,8 +112,7 @@ bool HTTP::Download(const std::string& IP, const std::string& Path) {
|
||||
std::string Ret = Get(IP);
|
||||
isDownload = false;
|
||||
|
||||
if (Ret.empty())
|
||||
return false;
|
||||
if (Ret.empty()) return false;
|
||||
std::cout << "\n";
|
||||
std::ofstream File(Path, std::ios::binary);
|
||||
if (File.is_open()) {
|
||||
|
||||
+10
-7
@@ -50,7 +50,9 @@ std::string Launcher::Login(const std::string& fields) {
|
||||
|
||||
if (Buffer.at(0) != '{' || d.is_discarded()) {
|
||||
LOG(ERROR) << Buffer;
|
||||
return GetFail("Invalid answer from authentication servers, please try again later!");
|
||||
return GetFail(
|
||||
"Invalid answer from authentication servers, please try again "
|
||||
"later!");
|
||||
}
|
||||
|
||||
if (!d["success"].is_null() && d["success"].get<bool>()) {
|
||||
@@ -62,8 +64,7 @@ std::string Launcher::Login(const std::string& fields) {
|
||||
PublicKey = d["public_key"].get<std::string>();
|
||||
}
|
||||
LOG(INFO) << "Authentication successful!";
|
||||
} else
|
||||
LOG(WARNING) << "Authentication failed!";
|
||||
} else LOG(WARNING) << "Authentication failed!";
|
||||
|
||||
if (!d["message"].is_null()) {
|
||||
d.erase("private_key");
|
||||
@@ -82,12 +83,15 @@ void Launcher::CheckKey() {
|
||||
Key.read(&Buffer[0], std::streamsize(Size));
|
||||
Key.close();
|
||||
|
||||
Buffer = HTTP::Post("https://auth.beammp.com/userlogin", R"({"pk":")" + Buffer + "\"}");
|
||||
Buffer = HTTP::Post("https://auth.beammp.com/userlogin",
|
||||
R"({"pk":")" + Buffer + "\"}");
|
||||
|
||||
Json d = Json::parse(Buffer, nullptr, false);
|
||||
if (Buffer == "-1" || Buffer.at(0) != '{' || d.is_discarded()) {
|
||||
LOG(DEBUG) << Buffer;
|
||||
LOG(FATAL) << "Invalid answer from authentication servers, please try again later!";
|
||||
LOG(FATAL)
|
||||
<< "Invalid answer from authentication servers, please try "
|
||||
"again later!";
|
||||
throw ShutdownException("Fatal Error");
|
||||
}
|
||||
if (d["success"].get<bool>()) {
|
||||
@@ -104,6 +108,5 @@ void Launcher::CheckKey() {
|
||||
LOG(WARNING) << "Could not open saved key!";
|
||||
UpdateKey("");
|
||||
}
|
||||
} else
|
||||
UpdateKey("");
|
||||
} else UpdateKey("");
|
||||
}
|
||||
|
||||
+51
-54
@@ -3,9 +3,7 @@
|
||||
/// Copyright (c) 2021-present Anonymous275 read the LICENSE file for more info.
|
||||
///
|
||||
|
||||
#include "Launcher.h"
|
||||
#include "Logger.h"
|
||||
#include "Server.h"
|
||||
#include <ws2tcpip.h>
|
||||
#include <atomic>
|
||||
#include <cstring>
|
||||
#include <filesystem>
|
||||
@@ -14,21 +12,22 @@
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
#include <ws2tcpip.h>
|
||||
#include "Launcher.h"
|
||||
#include "Logger.h"
|
||||
#include "Server.h"
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
std::vector<std::string> Split(const std::string& String, const std::string& delimiter) {
|
||||
std::vector<std::string> Split(const std::string& String,
|
||||
const std::string& delimiter) {
|
||||
std::vector<std::string> Val;
|
||||
size_t pos;
|
||||
std::string token, s = String;
|
||||
while ((pos = s.find(delimiter)) != std::string::npos) {
|
||||
token = s.substr(0, pos);
|
||||
if (!token.empty())
|
||||
Val.push_back(token);
|
||||
if (!token.empty()) Val.push_back(token);
|
||||
s.erase(0, pos + delimiter.length());
|
||||
}
|
||||
if (!s.empty())
|
||||
Val.push_back(s);
|
||||
if (!s.empty()) Val.push_back(s);
|
||||
return Val;
|
||||
}
|
||||
|
||||
@@ -61,8 +60,7 @@ std::string Server::Auth() {
|
||||
}
|
||||
|
||||
TCPSend(LauncherInstance->getPublicKey());
|
||||
if (Terminate)
|
||||
return "";
|
||||
if (Terminate) return "";
|
||||
|
||||
Res = TCPRcv();
|
||||
if (Res.empty() || Res[0] != 'P') {
|
||||
@@ -79,8 +77,7 @@ std::string Server::Auth() {
|
||||
return "";
|
||||
}
|
||||
TCPSend("SR");
|
||||
if (Terminate)
|
||||
return "";
|
||||
if (Terminate) return "";
|
||||
|
||||
Res = TCPRcv();
|
||||
|
||||
@@ -100,13 +97,12 @@ std::string Server::Auth() {
|
||||
}
|
||||
|
||||
void Server::UpdateUl(bool D, const std::string& msg) {
|
||||
if (D)
|
||||
UStatus = "UlDownloading Resource " + msg;
|
||||
else
|
||||
UStatus = "UlLoading Resource " + msg;
|
||||
if (D) UStatus = "UlDownloading Resource " + msg;
|
||||
else UStatus = "UlLoading Resource " + msg;
|
||||
}
|
||||
|
||||
void Server::AsyncUpdate(uint64_t& Rcv, uint64_t Size, const std::string& Name) {
|
||||
void Server::AsyncUpdate(uint64_t& Rcv, uint64_t Size,
|
||||
const std::string& Name) {
|
||||
do {
|
||||
double pr = double(Rcv) / double(Size) * 100;
|
||||
std::string Per = std::to_string(trunc(pr * 10) / 10);
|
||||
@@ -125,8 +121,7 @@ char* Server::TCPRcvRaw(uint64_t Sock, uint64_t& GRcv, uint64_t Size) {
|
||||
uint64_t Rcv = 0;
|
||||
do {
|
||||
int Len = int(Size - Rcv);
|
||||
if (Len > 1000000)
|
||||
Len = 1000000;
|
||||
if (Len > 1000000) Len = 1000000;
|
||||
int32_t Temp = recv(Sock, &File[Rcv], Len, MSG_WAITALL);
|
||||
if (Temp < 1) {
|
||||
UUl("Socket Closed Code 1");
|
||||
@@ -163,7 +158,7 @@ uint64_t Server::InitDSock() {
|
||||
Terminate = true;
|
||||
return 0;
|
||||
}
|
||||
char Code[2] = { 'D', char(ClientID) };
|
||||
char Code[2] = {'D', char(ClientID)};
|
||||
if (send(DSock, Code, 2, 0) != 2) {
|
||||
KillSocket(DSock);
|
||||
Terminate = true;
|
||||
@@ -172,13 +167,14 @@ uint64_t Server::InitDSock() {
|
||||
return DSock;
|
||||
}
|
||||
|
||||
std::string Server::MultiDownload(uint64_t DSock, uint64_t Size, const std::string& Name) {
|
||||
|
||||
std::string Server::MultiDownload(uint64_t DSock, uint64_t Size,
|
||||
const std::string& Name) {
|
||||
uint64_t GRcv = 0, MSize = Size / 2, DSize = Size - MSize;
|
||||
|
||||
std::thread Au(&Server::AsyncUpdate, this, std::ref(GRcv), Size, Name);
|
||||
|
||||
std::packaged_task<char*()> task([&] { return TCPRcvRaw(TCPSocket, GRcv, MSize); });
|
||||
std::packaged_task<char*()> task(
|
||||
[&] { return TCPRcvRaw(TCPSocket, GRcv, MSize); });
|
||||
std::future<char*> f1 = task.get_future();
|
||||
std::thread Dt(std::move(task));
|
||||
Dt.detach();
|
||||
@@ -198,8 +194,7 @@ std::string Server::MultiDownload(uint64_t DSock, uint64_t Size, const std::stri
|
||||
return "";
|
||||
}
|
||||
|
||||
if (Au.joinable())
|
||||
Au.join();
|
||||
if (Au.joinable()) Au.join();
|
||||
|
||||
/// omg yes very ugly my god but i was in a rush will revisit
|
||||
std::string Ret(Size, 0);
|
||||
@@ -214,20 +209,22 @@ std::string Server::MultiDownload(uint64_t DSock, uint64_t Size, const std::stri
|
||||
|
||||
void Server::InvalidResource(const std::string& File) {
|
||||
UUl("Invalid mod \"" + File + "\"");
|
||||
LOG(WARNING) << "The server tried to sync \"" << File << "\" that is not a .zip file!";
|
||||
LOG(WARNING) << "The server tried to sync \"" << File
|
||||
<< "\" that is not a .zip file!";
|
||||
Terminate = true;
|
||||
}
|
||||
|
||||
void Server::SyncResources() {
|
||||
std::string Ret = Auth();
|
||||
if (Ret.empty())
|
||||
return;
|
||||
if (Ret.empty()) return;
|
||||
LOG(INFO) << "Checking Resources...";
|
||||
CheckForDir();
|
||||
|
||||
std::vector<std::string> list = Split(Ret, ";");
|
||||
std::vector<std::string> FNames(list.begin(), list.begin() + (list.size() / 2));
|
||||
std::vector<std::string> FSizes(list.begin() + (list.size() / 2), list.end());
|
||||
std::vector<std::string> FNames(list.begin(),
|
||||
list.begin() + (list.size() / 2));
|
||||
std::vector<std::string> FSizes(list.begin() + (list.size() / 2),
|
||||
list.end());
|
||||
list.clear();
|
||||
Ret.clear();
|
||||
|
||||
@@ -238,43 +235,42 @@ void Server::SyncResources() {
|
||||
t += name.substr(name.find_last_of('/') + 1) + ";";
|
||||
}
|
||||
}
|
||||
if (t.empty())
|
||||
ModList = "-";
|
||||
else
|
||||
ModList = t;
|
||||
if (t.empty()) ModList = "-";
|
||||
else ModList = t;
|
||||
t.clear();
|
||||
for (auto FN = FNames.begin(), FS = FSizes.begin(); FN != FNames.end() && !Terminate; ++FN, ++FS) {
|
||||
for (auto FN = FNames.begin(), FS = FSizes.begin();
|
||||
FN != FNames.end() && !Terminate; ++FN, ++FS) {
|
||||
auto pos = FN->find_last_of('/');
|
||||
auto ZIP = FN->find(".zip");
|
||||
if (ZIP == std::string::npos || FN->length() - ZIP != 4) {
|
||||
InvalidResource(*FN);
|
||||
return;
|
||||
}
|
||||
if (pos == std::string::npos)
|
||||
continue;
|
||||
if (pos == std::string::npos) continue;
|
||||
Amount++;
|
||||
}
|
||||
if (!FNames.empty())
|
||||
LOG(INFO) << "Syncing...";
|
||||
if (!FNames.empty()) LOG(INFO) << "Syncing...";
|
||||
SOCKET DSock = InitDSock();
|
||||
for (auto FN = FNames.begin(), FS = FSizes.begin(); FN != FNames.end() && !Terminate; ++FN, ++FS) {
|
||||
for (auto FN = FNames.begin(), FS = FSizes.begin();
|
||||
FN != FNames.end() && !Terminate; ++FN, ++FS) {
|
||||
auto pos = FN->find_last_of('/');
|
||||
if (pos != std::string::npos) {
|
||||
a = "Resources" + FN->substr(pos);
|
||||
} else
|
||||
continue;
|
||||
} else continue;
|
||||
Pos++;
|
||||
if (fs::exists(a)) {
|
||||
if (!std::all_of(FS->begin(), FS->end(), isdigit))
|
||||
continue;
|
||||
if (!std::all_of(FS->begin(), FS->end(), isdigit)) continue;
|
||||
if (fs::file_size(a) == std::stoull(*FS)) {
|
||||
UpdateUl(false, std::to_string(Pos) + "/" + std::to_string(Amount) + ": " + a.substr(a.find_last_of('/')));
|
||||
UpdateUl(false, std::to_string(Pos) + "/" + std::to_string(Amount) +
|
||||
": " + a.substr(a.find_last_of('/')));
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||
try {
|
||||
if (!fs::exists(LauncherInstance->getMPUserPath())) {
|
||||
fs::create_directories(LauncherInstance->getMPUserPath());
|
||||
}
|
||||
fs::copy_file(a, LauncherInstance->getMPUserPath() + a.substr(a.find_last_of('/')),
|
||||
fs::copy_file(a,
|
||||
LauncherInstance->getMPUserPath() +
|
||||
a.substr(a.find_last_of('/')),
|
||||
fs::copy_options::overwrite_existing);
|
||||
} catch (std::exception& e) {
|
||||
LOG(ERROR) << "Failed copy to the mods folder! " << e.what();
|
||||
@@ -283,8 +279,7 @@ void Server::SyncResources() {
|
||||
}
|
||||
WaitForConfirm();
|
||||
continue;
|
||||
} else
|
||||
remove(a.c_str());
|
||||
} else remove(a.c_str());
|
||||
}
|
||||
CheckForDir();
|
||||
std::string FName = a.substr(a.find_last_of('/'));
|
||||
@@ -298,13 +293,14 @@ void Server::SyncResources() {
|
||||
break;
|
||||
}
|
||||
|
||||
std::string Name = std::to_string(Pos) + "/" + std::to_string(Amount) + ": " + FName;
|
||||
std::string Name =
|
||||
std::to_string(Pos) + "/" + std::to_string(Amount) + ": " + FName;
|
||||
|
||||
Data = MultiDownload(DSock, std::stoull(*FS), Name);
|
||||
|
||||
if (Terminate)
|
||||
break;
|
||||
UpdateUl(false, std::to_string(Pos) + "/" + std::to_string(Amount) + ": " + FName);
|
||||
if (Terminate) break;
|
||||
UpdateUl(false, std::to_string(Pos) + "/" + std::to_string(Amount) +
|
||||
": " + FName);
|
||||
std::ofstream LFS;
|
||||
LFS.open(a.c_str(), std::ios_base::app | std::ios::binary);
|
||||
if (LFS.is_open()) {
|
||||
@@ -317,7 +313,8 @@ void Server::SyncResources() {
|
||||
if (!fs::exists(LauncherInstance->getMPUserPath())) {
|
||||
fs::create_directories(LauncherInstance->getMPUserPath());
|
||||
}
|
||||
fs::copy_file(a, LauncherInstance->getMPUserPath() + FName, fs::copy_options::overwrite_existing);
|
||||
fs::copy_file(a, LauncherInstance->getMPUserPath() + FName,
|
||||
fs::copy_options::overwrite_existing);
|
||||
}
|
||||
WaitForConfirm();
|
||||
}
|
||||
|
||||
+28
-47
@@ -6,15 +6,14 @@
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
|
||||
#include "Server.h"
|
||||
#include "Compressor.h"
|
||||
#include "Launcher.h"
|
||||
#include "Logger.h"
|
||||
#include <windows.h>
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#include "Compressor.h"
|
||||
#include "Launcher.h"
|
||||
#include "Logger.h"
|
||||
|
||||
Server::Server(Launcher* Instance)
|
||||
: LauncherInstance(Instance) {
|
||||
Server::Server(Launcher* Instance) : LauncherInstance(Instance) {
|
||||
WSADATA wsaData;
|
||||
int iRes = WSAStartup(514, &wsaData); // 2.2
|
||||
if (iRes != 0) {
|
||||
@@ -36,7 +35,8 @@ void Server::TCPClientMain() {
|
||||
return;
|
||||
}
|
||||
const char optval = 0;
|
||||
int status = ::setsockopt(TCPSocket, SOL_SOCKET, SO_DONTLINGER, &optval, sizeof(optval));
|
||||
int status = ::setsockopt(TCPSocket, SOL_SOCKET, SO_DONTLINGER, &optval,
|
||||
sizeof(optval));
|
||||
if (status < 0) {
|
||||
LOG(INFO) << "Failed to set DONTLINGER: " << GetSocketApiError();
|
||||
}
|
||||
@@ -73,15 +73,14 @@ void Server::StartUDP() {
|
||||
}
|
||||
|
||||
void Server::UDPSend(std::string Data) {
|
||||
if (ClientID == -1 || UDPSocket == -1)
|
||||
return;
|
||||
if (ClientID == -1 || UDPSocket == -1) return;
|
||||
if (Data.length() > 400) {
|
||||
std::string CMP(Zlib::Comp(Data));
|
||||
Data = "ABG:" + CMP;
|
||||
}
|
||||
std::string Packet = char(ClientID + 1) + std::string(":") + Data;
|
||||
int sendOk = sendto(UDPSocket, Packet.c_str(), int(Packet.size()), 0, (sockaddr*)UDPSockAddress.get(),
|
||||
sizeof(sockaddr_in));
|
||||
int sendOk = sendto(UDPSocket, Packet.c_str(), int(Packet.size()), 0,
|
||||
(sockaddr*)UDPSockAddress.get(), sizeof(sockaddr_in));
|
||||
if (sendOk == SOCKET_ERROR)
|
||||
LOG(ERROR) << "UDP Socket Error Code : " << GetSocketApiError();
|
||||
}
|
||||
@@ -94,15 +93,14 @@ void Server::UDPParser(std::string Packet) {
|
||||
}
|
||||
|
||||
void Server::UDPRcv() {
|
||||
sockaddr_in FromServer {};
|
||||
sockaddr_in FromServer{};
|
||||
int clientLength = sizeof(FromServer);
|
||||
ZeroMemory(&FromServer, clientLength);
|
||||
std::string Ret(10240, 0);
|
||||
if (UDPSocket == -1)
|
||||
return;
|
||||
int32_t Rcv = recvfrom(UDPSocket, &Ret[0], 10240, 0, (sockaddr*)&FromServer, &clientLength);
|
||||
if (Rcv == SOCKET_ERROR)
|
||||
return;
|
||||
if (UDPSocket == -1) return;
|
||||
int32_t Rcv = recvfrom(UDPSocket, &Ret[0], 10240, 0, (sockaddr*)&FromServer,
|
||||
&clientLength);
|
||||
if (Rcv == SOCKET_ERROR) return;
|
||||
UDPParser(Ret.substr(0, Rcv));
|
||||
}
|
||||
|
||||
@@ -114,8 +112,7 @@ void Server::UDPClient() {
|
||||
LauncherInstance->SendIPC("P" + std::to_string(ClientID), false);
|
||||
TCPSend("H");
|
||||
UDPSend("p");
|
||||
while (!Terminate)
|
||||
UDPRcv();
|
||||
while (!Terminate) UDPRcv();
|
||||
KillSocket(UDPSocket);
|
||||
}
|
||||
|
||||
@@ -133,12 +130,9 @@ void Server::Connect(const std::string& Data) {
|
||||
std::string port = Data.substr(Data.find(':') + 1);
|
||||
bool ValidPort = std::all_of(port.begin(), port.end(), ::isdigit);
|
||||
if (IP.find('.') == -1 || !ValidPort) {
|
||||
if (IP == "DNS")
|
||||
UStatus = "Connection Failed! (DNS Lookup Failed)";
|
||||
else if (!ValidPort)
|
||||
UStatus = "Connection Failed! (Invalid Port)";
|
||||
else
|
||||
UStatus = "Connection Failed! (WSA failed to start)";
|
||||
if (IP == "DNS") UStatus = "Connection Failed! (DNS Lookup Failed)";
|
||||
else if (!ValidPort) UStatus = "Connection Failed! (Invalid Port)";
|
||||
else UStatus = "Connection Failed! (WSA failed to start)";
|
||||
ModList = "-";
|
||||
Terminate.store(true);
|
||||
return;
|
||||
@@ -169,12 +163,8 @@ std::string Server::GetSocketApiError() {
|
||||
err = WSAGetLastError();
|
||||
|
||||
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
nullptr,
|
||||
err,
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
msgbuf,
|
||||
sizeof(msgbuf),
|
||||
nullptr);
|
||||
nullptr, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
msgbuf, sizeof(msgbuf), nullptr);
|
||||
|
||||
if (*msgbuf) {
|
||||
return std::to_string(WSAGetLastError()) + " - " + std::string(msgbuf);
|
||||
@@ -184,22 +174,17 @@ std::string Server::GetSocketApiError() {
|
||||
}
|
||||
|
||||
void Server::ServerSend(std::string Data, bool Rel) {
|
||||
if (Terminate || Data.empty())
|
||||
return;
|
||||
if (Terminate || Data.empty()) return;
|
||||
char C = 0;
|
||||
int DLen = int(Data.length());
|
||||
if (DLen > 3)
|
||||
C = Data.at(0);
|
||||
if (DLen > 3) C = Data.at(0);
|
||||
bool Ack = C == 'O' || C == 'T';
|
||||
if (C == 'N' || C == 'W' || C == 'Y' || C == 'V' || C == 'E' || C == 'C')
|
||||
Rel = true;
|
||||
if (Ack || Rel) {
|
||||
if (Ack || DLen > 1000)
|
||||
SendLarge(Data);
|
||||
else
|
||||
TCPSend(Data);
|
||||
} else
|
||||
UDPSend(Data);
|
||||
if (Ack || DLen > 1000) SendLarge(Data);
|
||||
else TCPSend(Data);
|
||||
} else UDPSend(Data);
|
||||
}
|
||||
|
||||
void Server::PingLoop() {
|
||||
@@ -247,8 +232,7 @@ const std::string& Server::getUIStatus() {
|
||||
}
|
||||
|
||||
std::string Server::GetAddress(const std::string& Data) {
|
||||
if (Data.find_first_not_of("0123456789.") == -1)
|
||||
return Data;
|
||||
if (Data.find_first_not_of("0123456789.") == -1) return Data;
|
||||
hostent* host;
|
||||
host = gethostbyname(Data.c_str());
|
||||
if (!host) {
|
||||
@@ -260,8 +244,7 @@ std::string Server::GetAddress(const std::string& Data) {
|
||||
}
|
||||
|
||||
int Server::KillSocket(uint64_t Dead) {
|
||||
if (Dead == (SOCKET)-1)
|
||||
return 0;
|
||||
if (Dead == (SOCKET)-1) return 0;
|
||||
shutdown(Dead, SD_BOTH);
|
||||
return closesocket(Dead);
|
||||
}
|
||||
@@ -289,7 +272,6 @@ bool Server::CheckBytes(int32_t Bytes) {
|
||||
}
|
||||
|
||||
void Server::TCPSend(const std::string& Data) {
|
||||
|
||||
if (TCPSocket == -1) {
|
||||
Terminate = true;
|
||||
UUl("Invalid Socket");
|
||||
@@ -363,7 +345,6 @@ std::string Server::TCPRcv() {
|
||||
Ret = Zlib::DeComp(Ret.substr(4));
|
||||
}
|
||||
|
||||
if (Ret[0] == 'E')
|
||||
UUl(Ret.substr(1));
|
||||
if (Ret[0] == 'E') UUl(Ret.substr(1));
|
||||
return Ret;
|
||||
}
|
||||
|
||||
+28
-33
@@ -17,22 +17,17 @@ VersionParser::VersionParser(const std::string& from_string) {
|
||||
}
|
||||
}
|
||||
|
||||
std::strong_ordering VersionParser::operator<=>(const VersionParser& rhs) const noexcept {
|
||||
std::strong_ordering VersionParser::operator<=>(
|
||||
const VersionParser& rhs) const noexcept {
|
||||
size_t const fields = std::min(data.size(), rhs.data.size());
|
||||
for (size_t i = 0; i != fields; ++i) {
|
||||
if (data[i] == rhs.data[i])
|
||||
continue;
|
||||
else if (data[i] < rhs.data[i])
|
||||
return std::strong_ordering::less;
|
||||
else
|
||||
return std::strong_ordering::greater;
|
||||
if (data[i] == rhs.data[i]) continue;
|
||||
else if (data[i] < rhs.data[i]) return std::strong_ordering::less;
|
||||
else return std::strong_ordering::greater;
|
||||
}
|
||||
if (data.size() == rhs.data.size())
|
||||
return std::strong_ordering::equal;
|
||||
else if (data.size() > rhs.data.size())
|
||||
return std::strong_ordering::greater;
|
||||
else
|
||||
return std::strong_ordering::less;
|
||||
if (data.size() == rhs.data.size()) return std::strong_ordering::equal;
|
||||
else if (data.size() > rhs.data.size()) return std::strong_ordering::greater;
|
||||
else return std::strong_ordering::less;
|
||||
}
|
||||
|
||||
bool VersionParser::operator==(const VersionParser& rhs) const noexcept {
|
||||
@@ -41,10 +36,12 @@ bool VersionParser::operator==(const VersionParser& rhs) const noexcept {
|
||||
|
||||
void Launcher::UpdateCheck() {
|
||||
std::string link;
|
||||
std::string HTTP = HTTP::Get("https://beammp.com/builds/launcher?version=true");
|
||||
std::string HTTP =
|
||||
HTTP::Get("https://beammp.com/builds/launcher?version=true");
|
||||
bool fallback = false;
|
||||
if (HTTP.find_first_of("0123456789") == std::string::npos) {
|
||||
HTTP = HTTP::Get("https://backup1.beammp.com/builds/launcher?version=true");
|
||||
HTTP =
|
||||
HTTP::Get("https://backup1.beammp.com/builds/launcher?version=true");
|
||||
fallback = true;
|
||||
if (HTTP.find_first_of("0123456789") == std::string::npos) {
|
||||
LOG(FATAL) << "Primary Servers Offline! sorry for the inconvenience!";
|
||||
@@ -53,13 +50,12 @@ void Launcher::UpdateCheck() {
|
||||
}
|
||||
if (fallback) {
|
||||
link = "https://backup1.beammp.com/builds/launcher?download=true";
|
||||
} else
|
||||
link = "https://beammp.com/builds/launcher?download=true";
|
||||
} else link = "https://beammp.com/builds/launcher?download=true";
|
||||
|
||||
std::string EP(CurrentPath.string()), Back(CurrentPath.parent_path().string() + "\\BeamMP-Launcher.back");
|
||||
std::string EP(CurrentPath.string()),
|
||||
Back(CurrentPath.parent_path().string() + "\\BeamMP-Launcher.back");
|
||||
|
||||
if (fs::exists(Back))
|
||||
remove(Back.c_str());
|
||||
if (fs::exists(Back)) remove(Back.c_str());
|
||||
std::string RemoteVer;
|
||||
for (char& c : HTTP) {
|
||||
if (std::isdigit(c) || c == '.') {
|
||||
@@ -85,12 +81,12 @@ void Launcher::UpdateCheck() {
|
||||
}
|
||||
}
|
||||
Relaunch();
|
||||
} else
|
||||
LOG(INFO) << "Launcher version is up to date";
|
||||
} else LOG(INFO) << "Launcher version is up to date";
|
||||
}
|
||||
|
||||
size_t DirCount(const std::filesystem::path& path) {
|
||||
return (size_t)std::distance(std::filesystem::directory_iterator { path }, std::filesystem::directory_iterator {});
|
||||
return (size_t)std::distance(std::filesystem::directory_iterator{path},
|
||||
std::filesystem::directory_iterator{});
|
||||
}
|
||||
|
||||
void Launcher::ResetMods() {
|
||||
@@ -99,7 +95,8 @@ void Launcher::ResetMods() {
|
||||
return;
|
||||
}
|
||||
if (DirCount(fs::path(MPUserPath)) > 3) {
|
||||
LOG(WARNING) << "mods/multiplayer will be cleared in 15 seconds, close to abort";
|
||||
LOG(WARNING)
|
||||
<< "mods/multiplayer will be cleared in 15 seconds, close to abort";
|
||||
std::this_thread::sleep_for(std::chrono::seconds(15));
|
||||
}
|
||||
fs::remove_all(MPUserPath);
|
||||
@@ -108,19 +105,16 @@ void Launcher::ResetMods() {
|
||||
|
||||
void Launcher::EnableMP() {
|
||||
std::string File(BeamUserPath + "mods\\db.json");
|
||||
if (!fs::exists(File))
|
||||
return;
|
||||
if (!fs::exists(File)) return;
|
||||
auto Size = fs::file_size(File);
|
||||
if (Size < 2)
|
||||
return;
|
||||
if (Size < 2) return;
|
||||
std::ifstream db(File);
|
||||
if (db.is_open()) {
|
||||
std::string Data(Size, 0);
|
||||
db.read(&Data[0], std::streamsize(Size));
|
||||
db.close();
|
||||
Json d = Json::parse(Data, nullptr, false);
|
||||
if (Data.at(0) != '{' || d.is_discarded())
|
||||
return;
|
||||
if (Data.at(0) != '{' || d.is_discarded()) return;
|
||||
if (!d["mods"].is_null() && !d["mods"]["multiplayerbeammp"].is_null()) {
|
||||
d["mods"]["multiplayerbeammp"]["active"] = true;
|
||||
std::ofstream ofs(File);
|
||||
@@ -138,8 +132,9 @@ void Launcher::SetupMOD() {
|
||||
ResetMods();
|
||||
EnableMP();
|
||||
LOG(INFO) << "Downloading mod please wait";
|
||||
HTTP::Download("https://backend.beammp.com/builds/client?download=true"
|
||||
"&pk="
|
||||
+ PublicKey + "&branch=" + TargetBuild,
|
||||
HTTP::Download(
|
||||
"https://backend.beammp.com/builds/client?download=true"
|
||||
"&pk=" +
|
||||
PublicKey + "&branch=" + TargetBuild,
|
||||
MPUserPath + "\\BeamMP.zip");
|
||||
}
|
||||
|
||||
+11
-14
@@ -4,32 +4,30 @@
|
||||
///
|
||||
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#include <set>
|
||||
#include <wx/wxprec.h>
|
||||
#include <set>
|
||||
#ifndef WX_PRECOMP
|
||||
#include "gifs.h"
|
||||
#include <wx/animate.h>
|
||||
#include <wx/mstream.h>
|
||||
#include <wx/wx.h>
|
||||
#include "gifs.h"
|
||||
|
||||
#endif
|
||||
class MyApp : public wxApp {
|
||||
public:
|
||||
public:
|
||||
virtual bool OnInit();
|
||||
};
|
||||
class MyFrame : public wxFrame {
|
||||
public:
|
||||
public:
|
||||
MyFrame();
|
||||
|
||||
private:
|
||||
private:
|
||||
void OnHello(wxCommandEvent& event);
|
||||
void OnExit(wxCommandEvent& event);
|
||||
void OnAbout(wxCommandEvent& event);
|
||||
static wxSize FixedSize;
|
||||
};
|
||||
enum {
|
||||
ID_Hello = 1
|
||||
};
|
||||
enum { ID_Hello = 1 };
|
||||
wxSize MyFrame::FixedSize(370, 400);
|
||||
|
||||
bool MyApp::OnInit() {
|
||||
@@ -38,8 +36,8 @@ bool MyApp::OnInit() {
|
||||
return true;
|
||||
}
|
||||
|
||||
MyFrame::MyFrame()
|
||||
: wxFrame(nullptr, wxID_ANY, "BeamMP V3.0", wxDefaultPosition, FixedSize) {
|
||||
MyFrame::MyFrame() :
|
||||
wxFrame(nullptr, wxID_ANY, "BeamMP V3.0", wxDefaultPosition, FixedSize) {
|
||||
// SetMaxSize(FixedSize);
|
||||
// SetMinSize(FixedSize);
|
||||
Center();
|
||||
@@ -65,8 +63,7 @@ MyFrame::MyFrame()
|
||||
|
||||
auto* m_ani = new wxAnimationCtrl(this, wxID_ANY);
|
||||
wxMemoryInputStream stream(gif::Logo, sizeof(gif::Logo));
|
||||
if (m_ani->Load(stream))
|
||||
m_ani->Play();
|
||||
if (m_ani->Load(stream)) m_ani->Play();
|
||||
|
||||
Bind(wxEVT_MENU, &MyFrame::OnHello, this, ID_Hello);
|
||||
Bind(wxEVT_MENU, &MyFrame::OnAbout, this, wxID_ABOUT);
|
||||
@@ -76,8 +73,8 @@ void MyFrame::OnExit(wxCommandEvent& event) {
|
||||
Close(true);
|
||||
}
|
||||
void MyFrame::OnAbout(wxCommandEvent& event) {
|
||||
wxMessageBox("This is a wxWidgets Hello World example",
|
||||
"About Hello World", wxOK | wxICON_INFORMATION);
|
||||
wxMessageBox("This is a wxWidgets Hello World example", "About Hello World",
|
||||
wxOK | wxICON_INFORMATION);
|
||||
}
|
||||
void MyFrame::OnHello(wxCommandEvent& event) {
|
||||
wxLogMessage("Hello world from wxWidgets!");
|
||||
|
||||
+1
-2
@@ -2541,5 +2541,4 @@ const unsigned char gif::Logo[30427] = {
|
||||
0x54, 0x60, 0x2a, 0x56, 0xf9, 0x40, 0x72, 0x48, 0xd1, 0x81, 0x5e, 0x5e,
|
||||
0x63, 0x02, 0x28, 0x40, 0x8a, 0x55, 0x48, 0x70, 0x02, 0x61, 0x96, 0x92,
|
||||
0x02, 0x96, 0xe1, 0x40, 0x62, 0x2e, 0x40, 0x1a, 0x86, 0x60, 0x00, 0x30,
|
||||
0xd5, 0x7c, 0x4a, 0x20, 0x00, 0x00, 0x3b
|
||||
};
|
||||
0xd5, 0x7c, 0x4a, 0x20, 0x00, 0x00, 0x3b};
|
||||
|
||||
+1
-1
@@ -6,6 +6,6 @@
|
||||
#pragma once
|
||||
|
||||
class gif {
|
||||
public:
|
||||
public:
|
||||
static const unsigned char Logo[30427];
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user