Hooks Run Before Module Loaded
Posted: Thu Feb 19, 2009 3:28 pm
I'm getting some errors when I load my module, and I think that it has to do with the hooks getting called before my modules is officially loaded, i.e. after MOD_INIT but before MOD_LOAD. Here is the relevant code (which is attempting to log things to a SQLite database):
When I am watching the debug output, I get a call to dblogmod_log (registered to HOOKTYPE_LOG) *before* my module gets loaded (MOD_LOAD). This causes some odd behavior with the network stuff, as I keep getting "Socket operation on non-socket" errors on the secondary listening port (using the sample config, *.8067). If I modify the code (shown below) to register for HOOKTYPE_LOG in MOD_LOAD, everything works fine, however I do not get the first thing that is logged (TIME SYNCH).
This code "works":
Is there a way to make sure that I get that first log message? Would I need to modify Unreal itself to delay that message till after the modules get loaded?
Thanks.
Code: Select all
DLLFUNC int MOD_TEST(dblog)(ModuleInfo *modinfo) {
HookAddEx(modinfo->handle, HOOKTYPE_CONFIGTEST, dblogmod_config_test);
HookAddEx(modinfo->handle, HOOKTYPE_CONFIGPOSTTEST, dblogmod_config_posttest);
return MOD_SUCCESS;
}
DLLFUNC int MOD_INIT(dblog)(ModuleInfo *modinfo) {
HookAddEx(modinfo->handle, HOOKTYPE_CONFIGRUN, dblogmod_config_run);
HookAddEx(modinfo->handle, HOOKTYPE_LOG, dblogmod_log);
return MOD_SUCCESS;
}
DLLFUNC int MOD_LOAD(dblog)(int module_load) {
fprintf(stderr, "DBLOG: Mod Load\n");
if (init_db_connection()) {
fprintf(stderr, "DBLOG: Mod Load Failed\n");
return MOD_FAILED;
}
if (dblogmod_log_log(0, NULL, "DBLog Module Loaded")) {
fprintf(stderr, "DBLOG: Mod Load Failed\n");
return MOD_FAILED;
}
return MOD_SUCCESS;
}
This code "works":
Code: Select all
DLLFUNC int MOD_TEST(dblog)(ModuleInfo *modinfo) {
HookAddEx(modinfo->handle, HOOKTYPE_CONFIGTEST, dblogmod_config_test);
HookAddEx(modinfo->handle, HOOKTYPE_CONFIGPOSTTEST, dblogmod_config_posttest);
return MOD_SUCCESS;
}
DLLFUNC int MOD_INIT(dblog)(ModuleInfo *modinfo) {
HookAddEx(modinfo->handle, HOOKTYPE_CONFIGRUN, dblogmod_config_run);
bcopy(modinfo,&DBLogMod,modinfo->size);
return MOD_SUCCESS;
}
DLLFUNC int MOD_LOAD(dblog)(int module_load) {
fprintf(stderr, "DBLOG: Mod Load\n");
if (init_db_connection()) {
fprintf(stderr, "DBLOG: Mod Load Failed\n");
return MOD_FAILED;
}
HookAddEx(DBLogMod.handle, HOOKTYPE_LOG, dblogmod_log_log);
if (dblogmod_log_log(0, NULL, "DBLog Module Loaded")) {
fprintf(stderr, "DBLOG: Mod Load Failed\n");
return MOD_FAILED;
}
return MOD_SUCCESS;
}
Thanks.