Created
November 9, 2022 15:13
-
-
Save ryuukk/d116e001e9377440ae911e54365475ac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void on_pretick(Engine* e) | |
{ | |
static if (USE_DLL) | |
{ | |
void unload_dll() | |
{ | |
FreeLibrary(h); | |
h = null; | |
main_loop = null; | |
dll_ok = false; | |
} | |
timer -= engine.delta_time; | |
if (timer <= 0) | |
{ | |
timer = 2.0; | |
WIN32_FILE_ATTRIBUTE_DATA newAttribs; | |
GetFileAttributesEx("game.dll", GET_FILEEX_INFO_LEVELS.GetFileExInfoStandard, &newAttribs); | |
if (CompareFileTime(&attribs.ftLastWriteTime, &newAttribs.ftLastWriteTime) == -1) | |
{ | |
attribs = newAttribs; | |
if (h) | |
{ | |
LINFO("new game.dll version, reloading.."); | |
LINFO("freeing old dll.."); | |
FreeLibrary(h); | |
h = null; | |
main_loop = null; | |
} | |
LINFO("loading game.dll.."); | |
h = LoadLibraryA("game.dll"); | |
main_loop = cast(dll_tick_t) GetProcAddress(h, "dll_tick"); | |
if (!h) | |
{ | |
LERRO("unnable to load game.dll"); | |
} | |
else if (!main_loop) | |
{ | |
LERRO("game.dll doesn't have dll_tick exported"); | |
unload_dll(); | |
} | |
else | |
{ | |
LINFO("successfully reloaded game.dll"); | |
dll_ok = true; | |
} | |
} | |
} | |
if (forceUnload) | |
{ | |
LINFO("game.dll unloaded by force"); | |
forceUnload = false; | |
unload_dll(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment