prepare c u b e

This commit is contained in:
ChrisMiuchiz 2019-09-22 19:17:15 -04:00
parent 66b0adfffb
commit 357d7fde4b
3 changed files with 70 additions and 8 deletions

View File

@ -0,0 +1,47 @@
int ChatHandler(wchar_t* msg) {
for (DLL* dll: modDLLs) {
if (dll->HandleChat) {
if ( ((int(*)(wchar_t*))dll->HandleChat)(msg) ){
return 1;
}
}
}
return 0;
}
void* ChatHandler_ptr = (void*)&ChatHandler;
void* ASMChatHandler_jmpback;
void* ASMChatHandler_bail;
void no_optimize ASMChatHandler() {
asm(PUSH_ALL
"mov rcx, rsi \n" // The message
PREPARE_STACK
"call [ChatHandler_ptr] \n"
RESTORE_STACK
// Did the handler return true?
"test al, al \n"
"jnz bail \n"
POP_ALL
// original code
"mov qword ptr [rbp+0x98], 7 \n"
"mov [rbp+0x90], r15 \n"
"jmp [ASMChatHandler_jmpback] \n"
"bail: \n"
POP_ALL
"jmp [ASMChatHandler_bail]"
);
}
void SetupChatHandler() {
WriteFarJMP(base+0x87611, (void*)&ASMChatHandler);
ASMChatHandler_jmpback = (void*)base+0x87624;
ASMChatHandler_bail = (void*)base+0x879B2;
}

View File

@ -12,7 +12,7 @@
#define MUST_IMPORT(dllname, name)\
dllname->name = GetProcAddress(dllname->handle, #name);\
if (!dllname->name) {\
printf("%s does not export " #name ".\n", dllname->fileName.c_str());\
Popup("Error", "%s does not export " #name ".\n", dllname->fileName.c_str());\
exit(1);\
}
@ -22,6 +22,9 @@ dllname->name = GetProcAddress(dllname->handle, #name);
#define PUSH_ALL "push rax\npush rbx\npush rcx\npush rdx\npush rsi\npush rdi\npush rbp\npush r8\npush r9\npush r10\npush r11\npush r12\npush r13\npush r14\npush r15\n"
#define POP_ALL "pop r15\npop r14\npop r13\npop r12\npop r11\npop r10\npop r9\npop r8\npop rbp\npop rdi\npop rsi\npop rdx\npop rcx\npop rbx\npop rax\n"
#define PREPARE_STACK "mov rax, rsp \n and rsp, 0xFFFFFFFFFFFFFFF0 \n push rax \n sub rsp, 0x28 \n"
#define RESTORE_STACK "add rsp, 0x28 \n pop rsp \n"
using namespace std;
@ -50,6 +53,12 @@ void SetupHandlers() {
SetupChatHandler();
}
void Popup(char* title, char* format, ... ){
char msg[512] = {0};
sprintf(msg, format);
MessageBoxA(0, msg, title, MB_OK | MB_ICONINFORMATION);
}
extern "C" __declspec(dllexport) BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
switch (fdwReason) {
case DLL_PROCESS_ATTACH:
@ -57,8 +66,6 @@ extern "C" __declspec(dllexport) BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD
SetupHandlers();
MessageBoxA(0, "hello!", "DLL Message", MB_OK | MB_ICONINFORMATION);
//Find mods
HANDLE hFind;
WIN32_FIND_DATA data;
@ -90,12 +97,12 @@ extern "C" __declspec(dllexport) BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD
int majorVersion = ((int(*)())dll->ModMajorVersion)();
int minorVersion = ((int(*)())dll->ModMinorVersion)();
if (majorVersion != MOD_MAJOR_VERSION) {
printf("%s has major version %d but requires %d.\n", dll->fileName.c_str(), majorVersion, MOD_MAJOR_VERSION);
Popup("Error", "%s has major version %d but requires %d.\n", dll->fileName.c_str(), majorVersion, MOD_MAJOR_VERSION);
exit(1);
}
if (minorVersion > MOD_MINOR_VERSION) {
printf("%s has minor version %d but requires %d or lower.\n", dll->fileName.c_str(), minorVersion, MOD_MINOR_VERSION);
Popup("Error", "%s has minor version %d but requires %d or lower.\n", dll->fileName.c_str(), minorVersion, MOD_MINOR_VERSION);
exit(1);
}
}

View File

@ -3,13 +3,21 @@
Supports injecting Cube World mods. DLLs must go in a folder called "Mods".
## Installing
Get the latest executable from Releases and place it in the same folder as Cube.exe
Get the latest executable from Releases and place it in the same folder as cubeworld.exe
https://github.com/ChrisMiuchiz/Cube-World-Mod-Launcher/releases
## Installing Mods
A "Mods" folder should be created in the same folder as Cube.exe, and mods should be installed by moving them into the Mods folder.
A "Mods" folder should be created in the same folder as cubeworld.exe, and mods should be installed by moving them into the Mods folder.
## Preparing cubeworld.exe
Since Cube World is using SteamStub obfuscation, you need to remove the obfuscation using [Steamless](https://github.com/atom0s/Steamless).
building flags: -m64 -masm=intel -static-libgcc -static-libstdc++
## Building the launcher or mods
This project will only ever support GCC. This program will not even build using MSVC, not only because the inline assembly syntax is different, but because support for inline assembly was removed for x86-64.
All mods MUST include cwmods.h from [cwsdk](https://github.com/ChrisMiuchiz/CWSDK) to function.
Compiler/Linker flags: `-m64 -masm=intel -static -static-libgcc -static-libstdc++`