Refactor to work on Linux / Unix, fix some compiler errors.

CMakeLists was also modified to make this work, but its scuffed
and i will hold on to that for a while longer
This commit is contained in:
Lion Kortlepel
2020-11-01 02:00:27 +01:00
parent 02fbe72eed
commit 8bc35fb82e
18 changed files with 254 additions and 41 deletions

View File

@@ -3,7 +3,12 @@
///
#pragma once
#ifdef __WIN32
#include <WS2tcpip.h>
#else
#include <arpa/inet.h>
#define SOCKET int
#endif
#include "Buffer.h"
#include <string>
#include <vector>
@@ -67,4 +72,4 @@ struct ClientInterface{
}
};
extern ClientInterface* CI;
extern ClientInterface* CI;

View File

@@ -11,7 +11,9 @@
#include <mutex>
#include <set>
#include <any>
namespace fs = std::experimental::filesystem;
namespace fs = std::filesystem;
struct LuaArg{
std::vector<std::any> args;
void PushArgs(lua_State *State){
@@ -64,4 +66,4 @@ public:
};
int CallFunction(Lua*lua,const std::string& FuncName,LuaArg* args);
int TriggerLuaEvent(const std::string& Event,bool local,Lua*Caller,LuaArg* arg,bool Wait);
extern std::set<Lua*> PluginEngine;
extern std::set<Lua*> PluginEngine;

View File

@@ -2,7 +2,11 @@
/// Created by Anonymous275 on 7/28/2020
///
#pragma once
#ifdef __linux
#define EXCEPTION_POINTERS void
#else
#include <WS2tcpip.h>
#endif
#include <string>
#include "Xor.h"
struct RSA{

View File

@@ -5,6 +5,7 @@
#include <string>
#include <array>
#include <cstdarg>
#include <cstdio>
#define BEGIN_NAMESPACE(x) namespace x {
#define END_NAMESPACE }
@@ -68,10 +69,10 @@ BEGIN_NAMESPACE(XorCompileTime)
public:
template <size_t... Is>
constexpr __forceinline XorString(const Char* str, std::index_sequence< Is... >) : _key(RandomChar< K >::value), _encrypted{ enc(str[Is])... }
constexpr inline XorString(const Char* str, std::index_sequence< Is... >) : _key(RandomChar< K >::value), _encrypted{ enc(str[Is])... }
{}
__forceinline decltype(auto) decrypt(){
inline decltype(auto) decrypt(){
for (size_t i = 0; i < N; ++i) {
_encrypted[i] = dec(_encrypted[i]);
}
@@ -83,14 +84,14 @@ BEGIN_NAMESPACE(XorCompileTime)
static auto w_printf = [](const char* fmt, ...) {
va_list args;
va_start(args, fmt);
vprintf_s(fmt, args);
vprintf(fmt, args);
va_end(args);
};
static auto w_printf_s = [](const char* fmt, ...) {
va_list args;
va_start(args, fmt);
vprintf_s(fmt, args);
vprintf(fmt, args);
va_end(args);
};
@@ -113,7 +114,7 @@ BEGIN_NAMESPACE(XorCompileTime)
static auto w_sprintf_s = [](char* buf, size_t buf_size, const char* fmt, ...) {
va_list args;
va_start(args, fmt);
vsprintf_s(buf, buf_size, fmt, args);
vsnprintf(buf, buf_size, fmt, args);
va_end(args);
};
@@ -121,7 +122,7 @@ BEGIN_NAMESPACE(XorCompileTime)
int ret;
va_list args;
va_start(args, fmt);
ret = vsprintf_s(buf, buf_size, fmt, args);
ret = vsnprintf(buf, buf_size, fmt, args);
va_end(args);
return ret;
};

30
include/UnixCompat.h Normal file
View File

@@ -0,0 +1,30 @@
// Author: lionkor
#pragma once
// This header defines unix equivalents of common win32 functions.
#ifndef __WIN32
#include <cassert>
#include <cstring>
#include <unistd.h>
// ZeroMemory is just a {0} or a memset(addr, 0, len), and it's a macro on MSVC
inline void ZeroMemory(void* dst, size_t len) {
assert(std::memset(dst, 0, len) != nullptr);
}
// provides unix equivalent of closesocket call in win32
inline void closesocket(int socket) {
close(socket);
}
#ifndef __try
#define __try
#endif
#ifndef __except
#define __except(x) /**/
#endif
#endif // __WIN32