mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2026-04-11 10:16:17 +00:00
lots of work, added atomic queue, changed githuyb workflows and added patterns with memory functions. Changed from MS Detours to MinHook.
now works with lua prototype
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
///
|
||||
|
||||
#pragma once
|
||||
#include "Memory/Detours.h"
|
||||
#include "Memory/Hook.h"
|
||||
#include "Memory/GELua.h"
|
||||
#include "Memory/IPC.h"
|
||||
#include <memory>
|
||||
@@ -15,13 +15,14 @@ public:
|
||||
static void EntryPoint();
|
||||
static void SendIPC(const std::string& Data);
|
||||
private:
|
||||
static std::unique_ptr<Detours> TickCountDetour;
|
||||
static std::unique_ptr<Detours> OpenJITDetour;
|
||||
static std::unique_ptr<IPC> IPCFromLauncher;
|
||||
static std::unique_ptr<IPC> IPCToLauncher;
|
||||
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 uint32_t GetTickCount_D();
|
||||
static uint64_t GameBaseAddr;
|
||||
static uint64_t DllBaseAddr;
|
||||
static int GetTickCount_D(void* GEState, void* Param2, void* Param3, void* Param4);
|
||||
static void IPCListener();
|
||||
};
|
||||
|
||||
@@ -10,12 +10,14 @@ typedef struct lua_State lua_State;
|
||||
typedef int (*lua_CFunction)(lua_State*);
|
||||
extern int lua_gettop(lua_State *L);
|
||||
namespace def {
|
||||
typedef unsigned long (*GetTickCount)();
|
||||
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);
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
///
|
||||
/// Created by Anonymous275 on 1/21/22
|
||||
/// Copyright (c) 2021-present Anonymous275 read the LICENSE file for more info.
|
||||
///
|
||||
|
||||
#pragma once
|
||||
class Detours{
|
||||
void* targetPtr;
|
||||
void* detourFunc;
|
||||
public:
|
||||
Detours(void* src, void* dest) : targetPtr(src), detourFunc(dest){};
|
||||
void Attach();
|
||||
void Detach();
|
||||
|
||||
private:
|
||||
bool Attached = false;
|
||||
};
|
||||
@@ -9,17 +9,19 @@
|
||||
class GELua {
|
||||
public:
|
||||
static void FindAddresses();
|
||||
static def::GetTickCount GetTickCount;
|
||||
static def::lua_open_jit lua_open_jit;
|
||||
static def::lua_push_fstring lua_push_fstring;
|
||||
static def::lua_get_field lua_get_field;
|
||||
static def::lua_p_call lua_p_call;
|
||||
static def::lua_createtable lua_createtable;
|
||||
static def::lua_pushcclosure lua_pushcclosure;
|
||||
static def::lua_setfield lua_setfield;
|
||||
static def::lua_settable lua_settable;
|
||||
static def::lua_tolstring lua_tolstring;
|
||||
static lua_State* State;
|
||||
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 {
|
||||
|
||||
48
include/Memory/Hook.h
Normal file
48
include/Memory/Hook.h
Normal file
@@ -0,0 +1,48 @@
|
||||
///
|
||||
/// Created by Anonymous275 on 1/21/22
|
||||
/// Copyright (c) 2021-present Anonymous275 read the LICENSE file for more info.
|
||||
///
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include "Memory/Memory.h"
|
||||
#include <MinHook.h>
|
||||
|
||||
#pragma once
|
||||
template <class FuncType>
|
||||
class Hook {
|
||||
FuncType targetPtr;
|
||||
FuncType detourFunc;
|
||||
bool Attached = false;
|
||||
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 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{};
|
||||
};
|
||||
@@ -45,4 +45,12 @@ namespace Patterns {
|
||||
"\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"
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user