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

107 lines
2.9 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"
2019-10-06 03:59:20 +08:00
#define CUBE_VERSION "1.0.0-1"
#define CUBE_PACKED_CRC 0xC7682619
#define CUBE_UNPACKED_CRC 0xBA092543
2019-09-22 01:12:00 +08:00
2019-10-06 03:59:20 +08:00
#define MODLOADER_CRC 0x39D18E98
2019-09-22 01:12:00 +08:00
2019-10-06 10:40:58 +08:00
char* CUBE_EXECUTABLE = "cubeworld.exe";
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) {
bool testMode = false;
if (argc >= 2 && !strcmp(argv[1], "test")) {
testMode = true;
printf("Test mode enabled. CRC checks will be bypassed.\n");
2019-10-06 10:40:58 +08:00
if (argc >= 3) {
CUBE_EXECUTABLE = argv[2];
}
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);
}
unsigned int checksum = crc32_file(CUBE_EXECUTABLE);
if (testMode) {
printf("%s CRC: %08X\n", CUBE_EXECUTABLE, checksum);
}
// Check if the game is still packed
if (checksum == CUBE_PACKED_CRC && !testMode) {
printf("Cube World was found, but it is not unpacked.\n"
"Use Steamless to unpack %s.\n", CUBE_EXECUTABLE);
return Bail(1);
2019-09-11 07:28:59 +08:00
}
2019-09-22 01:12:00 +08:00
if (checksum != CUBE_UNPACKED_CRC && !testMode) {
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",
2019-09-22 01:12:00 +08:00
CUBE_VERSION, checksum, CUBE_UNPACKED_CRC);
return Bail(1);
2019-09-11 07:28:59 +08:00
}
2019-09-13 08:41:28 +08:00
//Inject our dll
if ( !FileExists("CubeModLoader.dll") ) {
2019-09-22 01:12:00 +08:00
printf("CubeModLoader.dll not found.\n");
return Bail(1);
}
unsigned int loaderChecksum = crc32_file("CubeModLoader.dll");
if (loaderChecksum != MODLOADER_CRC && !testMode) {
printf("CubeModLoader.dll is the wrong version (%08X)\n", loaderChecksum);
return Bail(1);
}
if (testMode) {
printf("CubeModLoader.dll CRC: %08X\n", loaderChecksum);
2019-09-11 07:28:59 +08:00
}
2019-09-22 01:12:00 +08:00
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-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;
}