Cube-World-Mod-Launcher/CubeModLauncher/main.cpp

68 lines
1.7 KiB
C++
Raw Normal View History

2019-09-11 07:28:59 +08:00
#include "main.h"
#include <iostream>
#include <windows.h>
#include <vector>
#include "Process.h"
#include "crc.h"
#define CUBE_VERSION "1.0.0-0"
2019-09-12 09:45:36 +08:00
#define CUBE_CRC 0xDC91320A
2019-09-11 07:28:59 +08:00
using namespace std;
bool FileExists(const char* fileName) {
DWORD dwAttrib = GetFileAttributes(fileName);
return (dwAttrib != INVALID_FILE_ATTRIBUTES && !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY));
}
2019-09-13 08:41:28 +08:00
int main() {
2019-09-11 07:28:59 +08:00
//Cube world is obviously required
2019-09-13 08:41:28 +08:00
if (!FileExists("Cube.exe")) {
2019-09-11 07:28:59 +08:00
printf("Cube World not found.\n");
Sleep(1000);
return 1;
}
unsigned int checksum = crc32_file("Cube.exe");
2019-09-13 08:41:28 +08:00
if (checksum != CUBE_CRC) {
2019-09-11 07:28:59 +08:00
printf("Cube World was found, but it is not version %s.\n"
"(Found CRC %08X, expected %08X)\n"
"Please update your game.\n",
CUBE_VERSION, checksum, CUBE_CRC);
printf("Press enter to exit.\n");
cin.ignore();
return 1;
}
2019-09-13 08:41:28 +08:00
//Inject our dll
if ( !FileExists("CubeModLoader.dll") ) {
2019-09-11 07:28:59 +08:00
printf("Callback manager not found.\n");
Sleep(1000);
return 1;
}
Process process("Cube.exe");
//Create game in suspended state
printf("Starting Cube.exe...\n\n");
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());
return 1;
2019-09-13 08:41:28 +08:00
} else {
2019-09-11 07:28:59 +08:00
printf("Cube.exe was successfully started.\n\n");
}
2019-09-13 08:41:28 +08:00
process.InjectDLL( std::string("CubeModLoader.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;
}