diff --git a/CubeModLauncher/main.cpp b/CubeModLauncher/main.cpp index efbcd95..cd74fdd 100644 --- a/CubeModLauncher/main.cpp +++ b/CubeModLauncher/main.cpp @@ -15,18 +15,16 @@ bool FileExists(const char* fileName) { return (dwAttrib != INVALID_FILE_ATTRIBUTES && !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY)); } -int main() -{ - vector modDLLs; +int main() { //Cube world is obviously required - if (!FileExists("Cube.exe")){ + if (!FileExists("Cube.exe")) { printf("Cube World not found.\n"); Sleep(1000); return 1; } unsigned int checksum = crc32_file("Cube.exe"); - if (checksum != CUBE_CRC){ + if (checksum != CUBE_CRC) { printf("Cube World was found, but it is not version %s.\n" "(Found CRC %08X, expected %08X)\n" "Please update your game.\n", @@ -36,52 +34,33 @@ int main() return 1; } - //The callback manager is required. - /*if ( !FileExists("CallbackManager.dll") ){ + //Inject our dll + if ( !FileExists("CubeModLoader.dll") ) { printf("Callback manager not found.\n"); Sleep(1000); return 1; } - modDLLs.push_back( std::string("CallbackManager.dll") ); - */ - Process process("Cube.exe"); //Create game in suspended state printf("Starting Cube.exe...\n\n"); - if (!process.Create()) - { + if (!process.Create()) { printf("Failed to create process: %lu", GetLastError()); return 1; - } - else { + } else { printf("Cube.exe was successfully started.\n\n"); } - //Find mods - HANDLE hFind; - WIN32_FIND_DATA data; + process.InjectDLL( std::string("CubeModLoader.dll") ); - CreateDirectory("Mods", NULL); - hFind = FindFirstFile("Mods\\*.dll", &data); - if (hFind != INVALID_HANDLE_VALUE) { - do { - modDLLs.push_back( std::string("Mods\\") + data.cFileName); - } while (FindNextFile(hFind, &data)); - FindClose(hFind); - } + // Need to give the loader some time to work + // This is a horrible thing and probably will result in a race condition please help me + Sleep(250); - - //Inject DLLs - for (string S_DLLName : modDLLs){ - printf("Loading %s\n", S_DLLName.c_str()); - process.InjectDLL(S_DLLName); - } - - printf("\nAll available mods have been loaded.\n"); - Sleep(1500); + // Let Cube World run! process.Run(); + Sleep(3000); return 0; diff --git a/CubeModLoader/main.cpp b/CubeModLoader/main.cpp new file mode 100644 index 0000000..99ce1d8 --- /dev/null +++ b/CubeModLoader/main.cpp @@ -0,0 +1,33 @@ +#include +#include +#include + +using namespace std; + +extern "C" __declspec(dllexport) BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { + switch (fdwReason) { + case DLL_PROCESS_ATTACH: + MessageBoxA(0, "hello!", "DLL Message", MB_OK | MB_ICONINFORMATION); + + vector modDLLs; + + //Find mods + HANDLE hFind; + WIN32_FIND_DATA data; + + CreateDirectory("Mods", NULL); + hFind = FindFirstFile("Mods\\*.dll", &data); + if (hFind != INVALID_HANDLE_VALUE) { + do { + modDLLs.push_back( std::string("Mods\\") + data.cFileName); + } while (FindNextFile(hFind, &data)); + FindClose(hFind); + } + + // We should be loaded into the application's address space, so we can just LoadLibraryA + for (std::string modName : modDLLs) { + LoadLibraryA(modName.c_str()); + } + } + return true; +}