This commit is contained in:
ChrisMiuchiz 2019-09-14 19:59:24 -04:00
parent 89da8bb31a
commit 176c0b95eb
4 changed files with 34 additions and 6 deletions

View File

@ -8,6 +8,9 @@ DLL::DLL(std::string fileName) {
HMODULE DLL::Load() {
this->handle = LoadLibraryA(this->fileName.c_str());
if (!this->handle) {
printf("%s %d\n", this->fileName.c_str(), GetLastError());
}
return this->handle;
}

View File

@ -9,6 +9,7 @@ class DLL
std::string fileName;
HMODULE handle;
FARPROC ModPreInitialize;
FARPROC ModInitialize;
FARPROC ModMajorVersion;
FARPROC ModMinorVersion;

View File

@ -102,23 +102,47 @@ extern "C" __declspec(dllexport) BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD
// We should be loaded into the application's address space, so we can just LoadLibraryA
DLL* dll = new DLL(string("Mods\\") + data.cFileName);
dll->Load();
printf("Loaded %s\n", dll->fileName.c_str());
modDLLs.push_back(dll);
} while (FindNextFile(hFind, &data));
FindClose(hFind);
}
// Find all the functions the mods may export
for (DLL* dll: modDLLs) {
MUST_IMPORT(dll, ModMajorVersion);
MUST_IMPORT(dll, ModMinorVersion);
MUST_IMPORT(dll, ModInitialize);
MUST_IMPORT(dll, ModPreInitialize);
IMPORT(dll, ModInitialize);
IMPORT(dll, HandleNumber);
}
// Ensure version compatibility
for (DLL* dll: modDLLs) {
int majorVersion = ((int(*)())dll->ModMajorVersion)();
int minorVersion = ((int(*)())dll->ModMinorVersion)();
if (majorVersion != MOD_MAJOR_VERSION) {
printf("%s has major version %d but requires %d.\n", dll->fileName.c_str(), majorVersion, MOD_MAJOR_VERSION);
exit(1);
}
if (minorVersion > MOD_MINOR_VERSION) {
printf("%s has minor version %d but requires %d or lower.\n", dll->fileName.c_str(), minorVersion, MOD_MINOR_VERSION);
exit(1);
}
}
// Run Initialization routines on all mods
for (DLL* dll: modDLLs) {
((void(*)())dll->ModInitialize)();
((void(*)())dll->ModPreInitialize)();
}
for (DLL* dll: modDLLs) {
if (dll->ModInitialize) {
((void(*)())dll->ModInitialize)();
}
}
}

View File

@ -2,10 +2,6 @@
Supports injecting Cube World mods. DLLs must go in a folder called "Mods".
If something doesn't work, make sure you have the latest release for the launcher and all your mods, along with Cube World.
If you need to update Cube World, you can use this: https://github.com/ChrisMiuchiz/CubeWorld-Cracker
## Installing
Get the latest executable from Releases and place it in the same folder as Cube.exe
@ -13,3 +9,7 @@ https://github.com/ChrisMiuchiz/Cube-World-Mod-Launcher/releases
## Installing Mods
A "Mods" folder should be created in the same folder as Cube.exe, and mods should be installed by moving them into the Mods folder.
building flags: -m64 -masm=intel -static-libgcc -static-libstdc++