From 098fd15371ed51a2a34840c5beee7e7cacc575d0 Mon Sep 17 00:00:00 2001 From: ChrisMiuchiz Date: Sat, 5 Oct 2019 15:59:20 -0400 Subject: [PATCH] Update to 1.0.0-1 --- CubeModLauncher/main.cpp | 8 +-- CubeModLoader/DLL.h | 1 + CubeModLoader/callbacks/ChatHandler.h | 12 ++-- CubeModLoader/callbacks/P2PRequestHandler.h | 62 +++++++++++++++++++++ CubeModLoader/main.cpp | 7 ++- 5 files changed, 78 insertions(+), 12 deletions(-) create mode 100644 CubeModLoader/callbacks/P2PRequestHandler.h diff --git a/CubeModLauncher/main.cpp b/CubeModLauncher/main.cpp index 0bb7d46..bcd0c68 100644 --- a/CubeModLauncher/main.cpp +++ b/CubeModLauncher/main.cpp @@ -5,11 +5,11 @@ #include "Process.h" #include "crc.h" -#define CUBE_VERSION "0.9.1-4" -#define CUBE_PACKED_CRC 0x4CC03A4E -#define CUBE_UNPACKED_CRC 0x6F879A76 +#define CUBE_VERSION "1.0.0-1" +#define CUBE_PACKED_CRC 0xC7682619 +#define CUBE_UNPACKED_CRC 0xBA092543 -#define MODLOADER_CRC 0x2201A3EA +#define MODLOADER_CRC 0x39D18E98 #define CUBE_EXECUTABLE "cubeworld.exe" diff --git a/CubeModLoader/DLL.h b/CubeModLoader/DLL.h index 5881351..df71319 100644 --- a/CubeModLoader/DLL.h +++ b/CubeModLoader/DLL.h @@ -16,6 +16,7 @@ class DLL // Callbacks FARPROC HandleChat; + FARPROC HandleP2PRequest; DLL(std::string fileName); HMODULE Load(); diff --git a/CubeModLoader/callbacks/ChatHandler.h b/CubeModLoader/callbacks/ChatHandler.h index 54896e8..d6f223c 100644 --- a/CubeModLoader/callbacks/ChatHandler.h +++ b/CubeModLoader/callbacks/ChatHandler.h @@ -30,9 +30,9 @@ void no_optimize ASMChatHandler() { POP_ALL // original code - "mov qword ptr [rbp+0x78], 7 \n" - "mov [rbp+0x70], r12 \n" - "mov [rbp+0x60], r12w \n" + "mov qword ptr [rbp+0x88], 7 \n" + "mov [rbp+0x80], r12 \n" + "mov [rbp+0x70], r12w \n" "jmp [ASMChatHandler_jmpback] \n" @@ -42,7 +42,7 @@ void no_optimize ASMChatHandler() { ); } void SetupChatHandler() { - WriteFarJMP(base+0x97108, (void*)&ASMChatHandler); - ASMChatHandler_jmpback = (void*)base+0x9711A; - ASMChatHandler_bail = (void*)base+0x9785A; + WriteFarJMP(base+0x97198, (void*)&ASMChatHandler); + ASMChatHandler_jmpback = (void*)base+0x971B0; + ASMChatHandler_bail = (void*)base+0x9777A; } diff --git a/CubeModLoader/callbacks/P2PRequestHandler.h b/CubeModLoader/callbacks/P2PRequestHandler.h new file mode 100644 index 0000000..18cde89 --- /dev/null +++ b/CubeModLoader/callbacks/P2PRequestHandler.h @@ -0,0 +1,62 @@ +int P2PRequestHandler(long long steamID) { + for (DLL* dll: modDLLs) { + if (dll->HandleP2PRequest) { + if ( int result = ((int(*)(long long))dll->HandleP2PRequest)(steamID) ){ + return result; + } + } + } + return 0; +} +void* P2PRequestHandler_ptr = (void*)&P2PRequestHandler; + +void* ASMP2PRequestHandler_jmpback; +void* ASMP2PRequestHandler_block; +void* ASMP2PRequestHandler_allow; +void no_optimize ASMP2PRequestHandler() { + asm(PUSH_ALL + + "mov rcx, [rdi] \n" //incoming steam id + + PREPARE_STACK + + "call [P2PRequestHandler_ptr] \n" + + RESTORE_STACK + + // Did the handler return 1? block + "cmp eax, 1 \n" + "je 1f \n" + + // Did the handler return 2? allow + "cmp eax, 2 \n" + "je 2f \n" + + // Otherwise? Do nothing + + POP_ALL + + // original code + "mov edx, 4 \n" + "mov rcx, [rax] \n" + "mov rax, [rcx] \n" + "call qword ptr [rax+0x18] \n" + + "jmp [ASMP2PRequestHandler_jmpback] \n" + + + "1: \n" //block + POP_ALL + "jmp [ASMP2PRequestHandler_block] \n" + + "2: \n" //allow + POP_ALL + "jmp [ASMP2PRequestHandler_allow] \n" + ); +} +void SetupP2PRequestHandler() { + WriteFarJMP(base+0x9F6DF, (void*)&ASMP2PRequestHandler); + ASMP2PRequestHandler_jmpback = (void*)base+0x9F6ED; + ASMP2PRequestHandler_block = (void*)base+0x9F7A6; + ASMP2PRequestHandler_allow = (void*)base+0x9F783; +} diff --git a/CubeModLoader/main.cpp b/CubeModLoader/main.cpp index fc3661c..aaff897 100644 --- a/CubeModLoader/main.cpp +++ b/CubeModLoader/main.cpp @@ -3,7 +3,7 @@ #include #include "DLL.h" -#define MOD_MAJOR_VERSION 3 +#define MOD_MAJOR_VERSION 4 #define MOD_MINOR_VERSION 1 @@ -49,10 +49,12 @@ void WriteFarJMP(void* source, void* destination) { VirtualProtect(location, 14, dwOldProtection, &dwOldProtection); } - #include "callbacks/ChatHandler.h" +#include "callbacks/ChatHandler.h" +#include "callbacks/P2PRequestHandler.h" void SetupHandlers() { SetupChatHandler(); + SetupP2PRequestHandler(); } void Popup(char* title, char* msg ){ @@ -90,6 +92,7 @@ extern "C" __declspec(dllexport) BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD MUST_IMPORT(dll, ModPreInitialize); IMPORT(dll, ModInitialize); IMPORT(dll, HandleChat); + IMPORT(dll, HandleP2PRequest); } // Ensure version compatibility