fix: quota maintain time is resetted on changelevel.

fix: crash without metamod after few map changes.
fix: move sprites precache into the correct place.
fix: move initialization stuff to post-ServerActivate.
This commit is contained in:
ds 2020-11-08 01:20:12 +03:00
commit 17b9200195
4 changed files with 44 additions and 47 deletions

View file

@ -673,6 +673,11 @@ public:
static DETOUR_RETURN CR_STDCALL replacement (SharedLibrary::Handle module, const char *function) { static DETOUR_RETURN CR_STDCALL replacement (SharedLibrary::Handle module, const char *function) {
return EntityLinkage::instance ().lookup (module, function); return EntityLinkage::instance ().lookup (module, function);
} }
public:
void clearExportTable () {
m_exports.clear ();
}
}; };
// expose globals // expose globals

View file

@ -60,8 +60,29 @@ void Game::levelInitialize (edict_t *entities, int max) {
// clear all breakables before initialization // clear all breakables before initialization
m_breakables.clear (); m_breakables.clear ();
// precache everything // initialize all config files
precache (); conf.loadConfigs ();
// update worldmodel
illum.resetWorldModel ();
// do level initialization stuff here...
graph.loadGraphData ();
// execute main config
conf.loadMainConfig ();
// load map-specific config
conf.loadMapSpecificConfig ();
// initialize quota management
bots.initQuota ();
// rebuild vistable if needed
graph.rebuildVisibility ();
// install the sendto hook to fake queries
util.installSendTo ();
// go thru the all entities on map, and do whatever we're want // go thru the all entities on map, and do whatever we're want
for (int i = 0; i < max; ++i) { for (int i = 0; i < max; ++i) {
@ -75,12 +96,6 @@ void Game::levelInitialize (edict_t *entities, int max) {
if (strcmp (classname, "worldspawn") == 0) { if (strcmp (classname, "worldspawn") == 0) {
m_startEntity = ent; m_startEntity = ent;
// initialize some structures
bots.initRound ();
// install the sendto hook to fake queries
util.installSendTo ();
} }
else if (strcmp (classname, "player_weaponstrip") == 0) { else if (strcmp (classname, "player_weaponstrip") == 0) {
if (is (GameFlags::Legacy) && strings.isEmpty (ent->v.target.chars ())) { if (is (GameFlags::Legacy) && strings.isEmpty (ent->v.target.chars ())) {
@ -90,9 +105,7 @@ void Game::levelInitialize (edict_t *entities, int max) {
engfuncs.pfnRemoveEntity (ent); engfuncs.pfnRemoveEntity (ent);
} }
} }
else if (strcmp (classname, "info_player_start") == 0) { else if (strcmp (classname, "info_player_start") == 0 || strcmp (classname, "info_vip_start") == 0) {
m_engineWrap.setModel (ent, "models/player/urban/urban.mdl");
ent->v.rendermode = kRenderTransAlpha; // set its render mode to transparency ent->v.rendermode = kRenderTransAlpha; // set its render mode to transparency
ent->v.renderamt = 127; // set its transparency amount ent->v.renderamt = 127; // set its transparency amount
ent->v.effects |= EF_NODRAW; ent->v.effects |= EF_NODRAW;
@ -100,21 +113,12 @@ void Game::levelInitialize (edict_t *entities, int max) {
++m_spawnCount[Team::CT]; ++m_spawnCount[Team::CT];
} }
else if (strcmp (classname, "info_player_deathmatch") == 0) { else if (strcmp (classname, "info_player_deathmatch") == 0) {
m_engineWrap.setModel (ent, "models/player/terror/terror.mdl");
ent->v.rendermode = kRenderTransAlpha; // set its render mode to transparency ent->v.rendermode = kRenderTransAlpha; // set its render mode to transparency
ent->v.renderamt = 127; // set its transparency amount ent->v.renderamt = 127; // set its transparency amount
ent->v.effects |= EF_NODRAW; ent->v.effects |= EF_NODRAW;
++m_spawnCount[Team::Terrorist]; ++m_spawnCount[Team::Terrorist];
} }
else if (strcmp (classname, "info_vip_start") == 0) {
m_engineWrap.setModel (ent, "models/player/vip/vip.mdl");
ent->v.rendermode = kRenderTransAlpha; // set its render mode to transparency
ent->v.renderamt = 127; // set its transparency amount
ent->v.effects |= EF_NODRAW;
}
else if (strcmp (classname, "func_vip_safetyzone") == 0 || strcmp (classname, "info_vip_safetyzone") == 0) { else if (strcmp (classname, "func_vip_safetyzone") == 0 || strcmp (classname, "info_vip_safetyzone") == 0) {
m_mapFlags |= MapFlags::Assassination; // assassination map m_mapFlags |= MapFlags::Assassination; // assassination map
} }

View file

@ -138,6 +138,9 @@ CR_EXPORT int GetEntityAPI (gamefuncs_t *table, int) {
bot->spawned (); bot->spawned ();
} }
// precache everything
game.precache ();
if (game.is (GameFlags::Metamod)) { if (game.is (GameFlags::Metamod)) {
RETURN_META_VALUE (MRES_IGNORED, 0); RETURN_META_VALUE (MRES_IGNORED, 0);
} }
@ -289,7 +292,7 @@ CR_EXPORT int GetEntityAPI (gamefuncs_t *table, int) {
dllapi.pfnClientCommand (ent); dllapi.pfnClientCommand (ent);
}; };
table->pfnServerActivate = [] (edict_t *pentEdictList, int edictCount, int clientMax) { table->pfnServerActivate = [] (edict_t *edictList, int edictCount, int clientMax) {
// this function is called when the server has fully loaded and is about to manifest itself // this function is called when the server has fully loaded and is about to manifest itself
// on the network as such. Since a mapchange is actually a server shutdown followed by a // on the network as such. Since a mapchange is actually a server shutdown followed by a
// restart, this function is also called when a new map is being loaded. Hence it's the // restart, this function is also called when a new map is being loaded. Hence it's the
@ -297,32 +300,13 @@ CR_EXPORT int GetEntityAPI (gamefuncs_t *table, int) {
// loading the bot profiles, and drawing the world map (ie, filling the navigation hashtable). // loading the bot profiles, and drawing the world map (ie, filling the navigation hashtable).
// Once this function has been called, the server can be considered as "running". // Once this function has been called, the server can be considered as "running".
conf.loadConfigs (); // initialize all config files
// do a level initialization
game.levelInitialize (pentEdictList, edictCount);
// update worldmodel
illum.resetWorldModel ();
// do level initialization stuff here...
graph.loadGraphData ();
// execute main config
conf.loadMainConfig ();
// load map-specific config
conf.loadMapSpecificConfig ();
// initialize quota management
bots.initQuota ();
if (game.is (GameFlags::Metamod)) { if (game.is (GameFlags::Metamod)) {
RETURN_META (MRES_IGNORED); RETURN_META (MRES_IGNORED);
} }
dllapi.pfnServerActivate (pentEdictList, edictCount, clientMax); dllapi.pfnServerActivate (edictList, edictCount, clientMax);
graph.rebuildVisibility (); // do a level initialization
game.levelInitialize (edictList, edictCount);
}; };
table->pfnServerDeactivate = [] () { table->pfnServerDeactivate = [] () {
@ -364,6 +348,9 @@ CR_EXPORT int GetEntityAPI (gamefuncs_t *table, int) {
RETURN_META (MRES_IGNORED); RETURN_META (MRES_IGNORED);
} }
dllapi.pfnServerDeactivate (); dllapi.pfnServerDeactivate ();
// refill export table
ents.clearExportTable ();
}; };
table->pfnStartFrame = [] () { table->pfnStartFrame = [] () {
@ -486,7 +473,7 @@ CR_LINKAGE_C int GetEntityAPI_Post (gamefuncs_t *table, int) {
RETURN_META (MRES_IGNORED); RETURN_META (MRES_IGNORED);
}; };
table->pfnServerActivate = [] (edict_t *, int, int) { table->pfnServerActivate = [] (edict_t *edictList, int edictCount, int) {
// this function is called when the server has fully loaded and is about to manifest itself // this function is called when the server has fully loaded and is about to manifest itself
// on the network as such. Since a mapchange is actually a server shutdown followed by a // on the network as such. Since a mapchange is actually a server shutdown followed by a
// restart, this function is also called when a new map is being loaded. Hence it's the // restart, this function is also called when a new map is being loaded. Hence it's the
@ -495,7 +482,8 @@ CR_LINKAGE_C int GetEntityAPI_Post (gamefuncs_t *table, int) {
// Once this function has been called, the server can be considered as "running". Post version // Once this function has been called, the server can be considered as "running". Post version
// called only by metamod. // called only by metamod.
graph.rebuildVisibility (); // do a level initialization
game.levelInitialize (edictList, edictCount);
RETURN_META (MRES_IGNORED); RETURN_META (MRES_IGNORED);
}; };

View file

@ -54,6 +54,8 @@ BotManager::BotManager () {
m_timeRoundEnd = 0.0f; m_timeRoundEnd = 0.0f;
m_autoKillCheckTime = 0.0f; m_autoKillCheckTime = 0.0f;
m_maintainTime = 0.0f;
m_quotaMaintainTime = 0.0f;
m_bombPlanted = false; m_bombPlanted = false;
m_botsCanPause = false; m_botsCanPause = false;
@ -470,8 +472,6 @@ void BotManager::maintainAutoKill () {
} }
void BotManager::reset () { void BotManager::reset () {
m_maintainTime = 0.0f;
m_quotaMaintainTime = 0.0f;
m_grenadeUpdateTime = 0.0f; m_grenadeUpdateTime = 0.0f;
m_entityUpdateTime = 0.0f; m_entityUpdateTime = 0.0f;
m_plantSearchUpdateTime = 0.0f; m_plantSearchUpdateTime = 0.0f;