Skip to content

Instantly share code, notes, and snippets.

@ryuukk
Created November 9, 2022 15:13
Show Gist options
  • Save ryuukk/d116e001e9377440ae911e54365475ac to your computer and use it in GitHub Desktop.
Save ryuukk/d116e001e9377440ae911e54365475ac to your computer and use it in GitHub Desktop.
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