This commit is contained in:
ChrisMiuchiz 2019-09-12 20:41:28 -04:00
parent a78fe0572e
commit a7f0179897
2 changed files with 46 additions and 34 deletions

View File

@ -15,9 +15,7 @@ bool FileExists(const char* fileName) {
return (dwAttrib != INVALID_FILE_ATTRIBUTES && !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY)); return (dwAttrib != INVALID_FILE_ATTRIBUTES && !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY));
} }
int main() int main() {
{
vector <std::string> modDLLs;
//Cube world is obviously required //Cube world is obviously required
if (!FileExists("Cube.exe")) { if (!FileExists("Cube.exe")) {
printf("Cube World not found.\n"); printf("Cube World not found.\n");
@ -36,52 +34,33 @@ int main()
return 1; return 1;
} }
//The callback manager is required. //Inject our dll
/*if ( !FileExists("CallbackManager.dll") ){ if ( !FileExists("CubeModLoader.dll") ) {
printf("Callback manager not found.\n"); printf("Callback manager not found.\n");
Sleep(1000); Sleep(1000);
return 1; return 1;
} }
modDLLs.push_back( std::string("CallbackManager.dll") );
*/
Process process("Cube.exe"); Process process("Cube.exe");
//Create game in suspended state //Create game in suspended state
printf("Starting Cube.exe...\n\n"); printf("Starting Cube.exe...\n\n");
if (!process.Create()) if (!process.Create()) {
{
printf("Failed to create process: %lu", GetLastError()); printf("Failed to create process: %lu", GetLastError());
return 1; return 1;
} } else {
else {
printf("Cube.exe was successfully started.\n\n"); printf("Cube.exe was successfully started.\n\n");
} }
//Find mods process.InjectDLL( std::string("CubeModLoader.dll") );
HANDLE hFind;
WIN32_FIND_DATA data;
CreateDirectory("Mods", NULL); // Need to give the loader some time to work
hFind = FindFirstFile("Mods\\*.dll", &data); // This is a horrible thing and probably will result in a race condition please help me
if (hFind != INVALID_HANDLE_VALUE) { Sleep(250);
do {
modDLLs.push_back( std::string("Mods\\") + data.cFileName);
} while (FindNextFile(hFind, &data));
FindClose(hFind);
}
// Let Cube World run!
//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);
process.Run(); process.Run();
Sleep(3000); Sleep(3000);
return 0; return 0;

33
CubeModLoader/main.cpp Normal file
View File

@ -0,0 +1,33 @@
#include <iostream>
#include <windows.h>
#include <vector>
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 <std::string> 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;
}