2019-09-11 07:28:59 +08:00
|
|
|
#include "main.h"
|
|
|
|
#include <iostream>
|
|
|
|
#include <windows.h>
|
|
|
|
#include <vector>
|
|
|
|
#include "Process.h"
|
2019-09-22 01:12:00 +08:00
|
|
|
|
2019-10-06 10:40:58 +08:00
|
|
|
char* CUBE_EXECUTABLE = "cubeworld.exe";
|
2019-10-13 05:18:14 +08:00
|
|
|
char* MODLOADER_DLL = "CubeModLoader.dll";
|
2019-09-11 07:28:59 +08:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2019-10-06 10:40:58 +08:00
|
|
|
bool FileExists(char* fileName) {
|
2019-09-11 07:28:59 +08:00
|
|
|
DWORD dwAttrib = GetFileAttributes(fileName);
|
|
|
|
return (dwAttrib != INVALID_FILE_ATTRIBUTES && !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY));
|
|
|
|
}
|
|
|
|
|
2019-09-22 01:12:00 +08:00
|
|
|
int Bail(int result){
|
|
|
|
printf("Press enter to exit.\n");
|
|
|
|
cin.ignore();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
2019-10-15 12:51:43 +08:00
|
|
|
if (argc >= 2) {
|
|
|
|
CUBE_EXECUTABLE = argv[1];
|
2019-09-22 01:12:00 +08:00
|
|
|
}
|
|
|
|
|
2019-09-11 07:28:59 +08:00
|
|
|
//Cube world is obviously required
|
2019-09-22 01:12:00 +08:00
|
|
|
if (!FileExists(CUBE_EXECUTABLE)) {
|
|
|
|
printf("%s not found.\n", CUBE_EXECUTABLE);
|
|
|
|
return Bail(1);
|
|
|
|
}
|
|
|
|
|
2019-09-13 08:41:28 +08:00
|
|
|
//Inject our dll
|
2019-10-13 05:18:14 +08:00
|
|
|
if ( !FileExists(MODLOADER_DLL) ) {
|
2019-10-14 01:28:23 +08:00
|
|
|
printf("%s not found.\n", MODLOADER_DLL);
|
2019-09-22 01:12:00 +08:00
|
|
|
return Bail(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
Process process(CUBE_EXECUTABLE);
|
2019-09-11 07:28:59 +08:00
|
|
|
|
|
|
|
//Create game in suspended state
|
2019-09-22 01:12:00 +08:00
|
|
|
printf("Starting %s...\n\n", CUBE_EXECUTABLE);
|
2019-09-13 08:41:28 +08:00
|
|
|
if (!process.Create()) {
|
2019-09-11 07:28:59 +08:00
|
|
|
printf("Failed to create process: %lu", GetLastError());
|
2019-09-22 01:12:00 +08:00
|
|
|
return Bail(1);
|
2019-09-13 08:41:28 +08:00
|
|
|
} else {
|
2019-09-22 01:12:00 +08:00
|
|
|
printf("%s was successfully started.\n\n", CUBE_EXECUTABLE);
|
2019-09-11 07:28:59 +08:00
|
|
|
}
|
|
|
|
|
2019-10-13 05:18:14 +08:00
|
|
|
process.InjectDLL( std::string(MODLOADER_DLL) );
|
2019-09-11 07:28:59 +08:00
|
|
|
|
2019-09-13 08:41:28 +08:00
|
|
|
// 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);
|
2019-09-11 07:28:59 +08:00
|
|
|
|
2019-09-13 08:41:28 +08:00
|
|
|
// Let Cube World run!
|
2019-09-12 09:45:36 +08:00
|
|
|
process.Run();
|
2019-09-13 08:41:28 +08:00
|
|
|
|
2019-09-12 09:45:36 +08:00
|
|
|
Sleep(3000);
|
2019-09-11 07:28:59 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|