clang format

This commit is contained in:
Anonymous275
2022-07-26 11:43:45 +03:00
parent b26fb43746
commit 3c96bb3959
34 changed files with 1912 additions and 1832 deletions

View File

@@ -7,7 +7,7 @@
#include <string>
class Zlib {
public:
static std::string DeComp(std::string Compressed);
static std::string Comp(std::string Data);
public:
static std::string DeComp(std::string Compressed);
static std::string Comp(std::string Data);
};

View File

@@ -7,12 +7,12 @@
#include <string>
class HTTP {
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:
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:
static bool isDownload;
public:
static bool isDownload;
};

View File

@@ -4,90 +4,90 @@
///
#pragma once
#include "Memory/IPC.h"
#include "Server.h"
#include <filesystem>
#include <thread>
#include "Memory/IPC.h"
#include "Server.h"
namespace fs = std::filesystem;
struct VersionParser {
explicit VersionParser(const std::string& from_string);
std::strong_ordering operator<=>(VersionParser const& rhs) const noexcept;
bool operator==(VersionParser const& rhs) const noexcept;
std::vector<std::string> split;
std::vector<size_t> data;
explicit VersionParser(const std::string& from_string);
std::strong_ordering operator<=>(VersionParser const& rhs) const noexcept;
bool operator==(VersionParser const& rhs) const noexcept;
std::vector<std::string> split;
std::vector<size_t> data;
};
class Launcher {
public: // constructors
Launcher(int argc, char* argv[]);
~Launcher();
public: // constructors
Launcher(int argc, char* argv[]);
~Launcher();
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);
void RunDiscordRPC();
void QueryRegistry();
void WaitForGame();
void LoadConfig();
void LaunchGame();
void CheckKey();
void SetupMOD();
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);
void RunDiscordRPC();
void QueryRegistry();
void WaitForGame();
void LoadConfig();
void LaunchGame();
void CheckKey();
void SetupMOD();
public: // Getters and Setters
void setDiscordMessage(const std::string& message);
static void setExit(bool exit) noexcept;
const std::string& getFullVersion();
const std::string& getMPUserPath();
static bool Terminated() noexcept;
const std::string& getPublicKey();
const std::string& getUserRole();
const std::string& getVersion();
static bool getExit() noexcept;
public: // Getters and Setters
void setDiscordMessage(const std::string& message);
static void setExit(bool exit) noexcept;
const std::string& getFullVersion();
const std::string& getMPUserPath();
static bool Terminated() noexcept;
const std::string& getPublicKey();
const std::string& getUserRole();
const std::string& getVersion();
static bool getExit() noexcept;
private: // functions
void HandleIPC(const std::string& Data);
std::string GetLocalAppdata();
void UpdatePresence();
void AdminRelaunch();
void RichPresence();
void WindowsInit();
void UpdateCheck();
void ResetMods();
void EnableMP();
void Relaunch();
void ListenIPC();
void Abort();
private: // functions
void HandleIPC(const std::string& Data);
std::string GetLocalAppdata();
void UpdatePresence();
void AdminRelaunch();
void RichPresence();
void WindowsInit();
void UpdateCheck();
void ResetMods();
void EnableMP();
void Relaunch();
void ListenIPC();
void Abort();
private: // variables
uint32_t GamePID { 0 };
bool EnableUI = true;
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 {};
private: // variables
uint32_t GamePID{0};
bool EnableUI = true;
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{};
};
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){};
};

View File

@@ -8,6 +8,6 @@
#undef min
#undef max
class Log {
public:
static void Init();
public:
static void Init();
};

View File

@@ -4,25 +4,27 @@
///
#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:
static void EntryPoint();
static void SendIPC(const std::string& Data);
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;
static inline std::unique_ptr<IPC> IPCToLauncher;
static inline uint64_t GameBaseAddr;
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 void IPCListener();
public:
static void EntryPoint();
static void SendIPC(const std::string& Data);
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;
static inline std::unique_ptr<IPC> IPCToLauncher;
static inline uint64_t GameBaseAddr;
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 void IPCListener();
};

View File

@@ -8,18 +8,19 @@
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 uint32_t (*GetTickCount)();
typedef int (*lua_open_jit)(lua_State* L);
typedef void (*lua_get_field)(lua_State* L, int idx, const char* k);
typedef const char* (*lua_push_fstring)(lua_State* L, const char* fmt, ...);
typedef int (*lua_p_call)(lua_State* L, int arg, int res, int err);
typedef void (*lua_pushcclosure)(lua_State* L, lua_CFunction fn, int n);
typedef int (*lua_settop)(lua_State* L, int idx);
typedef void (*lua_settable)(lua_State* L, int idx);
typedef void (*lua_createtable)(lua_State* L, int narray, int nrec);
typedef void (*lua_setfield)(lua_State* L, int idx, const char* k);
typedef const char* (*lua_tolstring)(lua_State* L, int idx, size_t* len);
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);
typedef const char* (*lua_push_fstring)(lua_State* L, const char* fmt, ...);
typedef int (*lua_p_call)(lua_State* L, int arg, int res, int err);
typedef void (*lua_pushcclosure)(lua_State* L, lua_CFunction fn, int n);
typedef int (*lua_settop)(lua_State* L, int idx);
typedef void (*lua_settable)(lua_State* L, int idx);
typedef void (*lua_createtable)(lua_State* L, int narray, int nrec);
typedef void (*lua_setfield)(lua_State* L, int idx, const char* k);
typedef const char* (*lua_tolstring)(lua_State* L, int idx, size_t* len);
}

View File

@@ -7,39 +7,40 @@
#include "Definitions.h"
class GELua {
public:
static void FindAddresses();
static inline def::GEUpdate GEUpdate;
static inline def::lua_settop lua_settop;
static inline def::GetTickCount GetTickCount;
static inline def::lua_open_jit lua_open_jit;
static inline def::lua_push_fstring lua_push_fstring;
static inline def::lua_get_field lua_get_field;
static inline def::lua_p_call lua_p_call;
static inline def::lua_createtable lua_createtable;
static inline def::lua_pushcclosure lua_pushcclosure;
static inline def::lua_setfield lua_setfield;
static inline def::lua_settable lua_settable;
static inline def::lua_tolstring lua_tolstring;
static inline lua_State* State;
public:
static void FindAddresses();
static inline def::GEUpdate GEUpdate;
static inline def::lua_settop lua_settop;
static inline def::GetTickCount GetTickCount;
static inline def::lua_open_jit lua_open_jit;
static inline def::lua_push_fstring lua_push_fstring;
static inline def::lua_get_field lua_get_field;
static inline def::lua_p_call lua_p_call;
static inline def::lua_createtable lua_createtable;
static inline def::lua_pushcclosure lua_pushcclosure;
static inline def::lua_setfield lua_setfield;
static inline def::lua_settable lua_settable;
static inline def::lua_tolstring lua_tolstring;
static inline lua_State* State;
};
namespace GELuaTable {
inline void Begin(lua_State* L) {
GELua::lua_createtable(L, 0, 0);
}
inline void End(lua_State* L, const char* name) {
GELua::lua_setfield(L, -10002, name);
}
inline void BeginEntry(lua_State* L, const char* name) {
GELua::lua_push_fstring(L, "%s", name);
}
inline void EndEntry(lua_State* L) {
GELua::lua_settable(L, -3);
}
inline void InsertFunction(lua_State* L, const char* name, lua_CFunction func) {
BeginEntry(L, name);
GELua::lua_pushcclosure(L, func, 0);
EndEntry(L);
}
inline void Begin(lua_State* L) {
GELua::lua_createtable(L, 0, 0);
}
inline void End(lua_State* L, const char* name) {
GELua::lua_setfield(L, -10002, name);
}
inline void BeginEntry(lua_State* L, const char* name) {
GELua::lua_push_fstring(L, "%s", name);
}
inline void EndEntry(lua_State* L) {
GELua::lua_settable(L, -3);
}
inline void InsertFunction(lua_State* L, const char* name,
lua_CFunction func) {
BeginEntry(L, name);
GELua::lua_pushcclosure(L, func, 0);
EndEntry(L);
}
}

View File

@@ -3,46 +3,49 @@
/// 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:
FuncType targetPtr;
FuncType detourFunc;
bool Attached = false;
Hook(FuncType src, FuncType dest) : targetPtr(src), detourFunc(dest) {
auto status = MH_CreateHook((void*)targetPtr, (void*)detourFunc, (void**)&Original);
if(status != MH_OK) {
Memory::Print(std::string("MH Error -> ") + MH_StatusToString(status));
public:
Hook(FuncType src, FuncType dest) : targetPtr(src), detourFunc(dest) {
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) {
auto status = MH_EnableHook((void*)targetPtr);
if (status != MH_OK) {
Memory::Print(std::string("MH Error -> ") +
MH_StatusToString(status));
return;
}
}
}
Attached = true;
}
}
void Enable() {
if(!Attached){
auto status = MH_EnableHook((void*)targetPtr);
if(status != MH_OK) {
Memory::Print(std::string("MH Error -> ") + MH_StatusToString(status));
return;
}
Attached = true;
}
}
void Disable() {
if (Attached) {
auto status = MH_DisableHook((void*)targetPtr);
if (status != MH_OK) {
Memory::Print(std::string("MH Error -> ") +
MH_StatusToString(status));
return;
}
Attached = false;
}
}
void Disable() {
if(Attached){
auto status = MH_DisableHook((void*)targetPtr);
if(status != MH_OK) {
Memory::Print(std::string("MH Error -> ") + MH_StatusToString(status));
return;
}
Attached = false;
}
}
FuncType Original{};
FuncType Original{};
};

View File

@@ -7,28 +7,29 @@
#include <string>
class IPC {
public:
IPC() = default;
IPC(uint32_t ID, size_t Size) noexcept;
[[nodiscard]] size_t size() const noexcept;
[[nodiscard]] char* c_str() const noexcept;
void send(const std::string& msg) noexcept;
[[nodiscard]] void* raw() const noexcept;
[[nodiscard]] bool receive_timed_out() const noexcept;
[[nodiscard]] bool send_timed_out() const noexcept;
const std::string& msg() noexcept;
void confirm_receive() noexcept;
void try_receive() noexcept;
void receive() noexcept;
~IPC() noexcept;
static bool mem_used(uint32_t MemID) noexcept;
private:
void* SemConfHandle_;
void* MemoryHandle_;
void* SemHandle_;
std::string Msg_;
bool SendTimeout;
bool RcvTimeout;
size_t Size_;
char* Data_;
public:
IPC() = default;
IPC(uint32_t ID, size_t Size) noexcept;
[[nodiscard]] size_t size() const noexcept;
[[nodiscard]] char* c_str() const noexcept;
void send(const std::string& msg) noexcept;
[[nodiscard]] void* raw() const noexcept;
[[nodiscard]] bool receive_timed_out() const noexcept;
[[nodiscard]] bool send_timed_out() const noexcept;
const std::string& msg() noexcept;
void confirm_receive() noexcept;
void try_receive() noexcept;
void receive() noexcept;
~IPC() noexcept;
static bool mem_used(uint32_t MemID) noexcept;
private:
void* SemConfHandle_;
void* MemoryHandle_;
void* SemHandle_;
std::string Msg_;
bool SendTimeout;
bool RcvTimeout;
size_t Size_;
char* Data_;
};

View File

@@ -4,17 +4,17 @@
///
#pragma once
#include <string>
#include <set>
#include <string>
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);
static void Print(const std::string& msg);
static void Inject(uint32_t PID);
static uint32_t GetTickCount();
static uint32_t EntryPoint();
static uint32_t GetPID();
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);
static void Print(const std::string& msg);
static void Inject(uint32_t PID);
static uint32_t GetTickCount();
static uint32_t EntryPoint();
static uint32_t GetPID();
};

View File

@@ -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] {
"\x4c\x8b\xc1\x85\xd2\x7e\x00\x48\x8b\x41\x00\x48\x8b\x49",
"xxxxxx?xxx?xxx"
};
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"};
}

View File

@@ -12,65 +12,67 @@
struct sockaddr_in;
class Launcher;
class Server {
public:
Server() = delete;
explicit Server(Launcher* Instance);
~Server();
public:
Server() = delete;
explicit Server(Launcher* Instance);
~Server();
public:
void ServerSend(std::string Data, bool Rel);
void Connect(const std::string& Data);
const std::string& getModList();
const std::string& getUIStatus();
const std::string& getMap();
void StartUDP();
void setModLoaded();
bool Terminated();
int getPing() const;
void Close();
public:
void ServerSend(std::string Data, bool Rel);
void Connect(const std::string& Data);
const std::string& getModList();
const std::string& getUIStatus();
const std::string& getMap();
void StartUDP();
void setModLoaded();
bool Terminated();
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);
void AsyncUpdate(uint64_t& Rcv, uint64_t Size, const std::string& Name);
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);
void UpdateUl(bool D, const std::string& msg);
std::unique_ptr<sockaddr_in> UDPSockAddress;
void ServerParser(const std::string& Data);
static std::string GetSocketApiError();
void TCPSend(const std::string& Data);
void UDPParser(std::string Packet);
void SendLarge(std::string Data);
void UDPSend(std::string Data);
void UUl(const std::string& R);
bool CheckBytes(int32_t Bytes);
int KillSocket(uint64_t Dead);
void MultiKill(uint64_t Sock);
Launcher* LauncherInstance;
std::thread TCPConnection;
std::thread UDPConnection;
std::thread AutoPing;
uint64_t TCPSocket = -1;
uint64_t UDPSocket = -1;
void WaitForConfirm();
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 {};
void UDPClient();
void PingLoop();
int ClientID { 0 };
void UDPMain();
void UDPRcv();
void Abort();
int Port { 0 };
int Ping { 0 };
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};
char* TCPRcvRaw(uint64_t Sock, uint64_t& GRcv, uint64_t Size);
std::string GetAddress(const std::string& Data);
void InvalidResource(const std::string& File);
void UpdateUl(bool D, const std::string& msg);
std::unique_ptr<sockaddr_in> UDPSockAddress;
void ServerParser(const std::string& Data);
static std::string GetSocketApiError();
void TCPSend(const std::string& Data);
void UDPParser(std::string Packet);
void SendLarge(std::string Data);
void UDPSend(std::string Data);
void UUl(const std::string& R);
bool CheckBytes(int32_t Bytes);
int KillSocket(uint64_t Dead);
void MultiKill(uint64_t Sock);
Launcher* LauncherInstance;
std::thread TCPConnection;
std::thread UDPConnection;
std::thread AutoPing;
uint64_t TCPSocket = -1;
uint64_t UDPSocket = -1;
void WaitForConfirm();
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{};
void UDPClient();
void PingLoop();
int ClientID{0};
void UDPMain();
void UDPRcv();
void Abort();
int Port{0};
int Ping{0};
};

View File

@@ -7,55 +7,51 @@
#include <queue>
#include <semaphore>
template <class T, size_t Size>
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;
}
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);
}
void push(const T& val) {
check_full();
lock_guard guard(semaphore);
queue.push(val);
}
size_t size() {
lock_guard guard(semaphore);
return queue.size();
}
size_t size() {
lock_guard guard(semaphore);
return queue.size();
}
bool empty() {
lock_guard guard(semaphore);
return queue.empty();
}
bool empty() {
lock_guard guard(semaphore);
return queue.empty();
}
private:
void check_full() {
if (size() >= Size) {
full.acquire();
}
}
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:
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 {};
private:
std::binary_semaphore& lock;
};
std::binary_semaphore semaphore{1}, full{0};
std::queue<T> queue{};
};