a little cleanup of code

This commit is contained in:
jeefo 2016-09-10 19:31:38 +03:00
commit c4d6ce3c45
14 changed files with 430 additions and 343 deletions

View file

@ -915,7 +915,7 @@ void CommandHandler_NotMM (void)
// the stdio command-line parsing in C when you write "long main (long argc, char **argv)".
// this function is handler for non-metamod launch of yapb, it's just print error message.
engine.Printf ("You're launched standalone version of yapb. Metamod is not installed or not enabled!");
}
void GameDLLInit (void)
@ -928,8 +928,6 @@ void GameDLLInit (void)
// server is enabled. Here is a good place to do our own game session initialization, and
// to register by the engine side the server commands we need to administrate our bots.
// register server command(s)
engine.RegisterCmd ("yapb", CommandHandler);
engine.RegisterCmd ("yb", CommandHandler);
@ -941,10 +939,15 @@ void GameDLLInit (void)
yb_version.SetString (FormatBuffer ("%d.%d.%d.%u", PRODUCT_VERSION_DWORD_INTERNAL, GenerateBuildNumber ()));
// register fake metamod command handler if we not! under mm
if (!g_isMetamod)
engine.RegisterCmd ("meta", CommandHandler_NotMM);
if (!(g_gameFlags & GAME_METAMOD))
{
engine.RegisterCmd ("meta", [] (void)
{
engine.Printf ("You're launched standalone version of yapb. Metamod is not installed or not enabled!");
});
}
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META (MRES_IGNORED);
(*g_functionTable.pfnGameInit) ();
@ -970,7 +973,7 @@ void Touch (edict_t *pentTouched, edict_t *pentOther)
if (bot != NULL)
bot->VerifyBreakable (pentTouched);
}
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META (MRES_IGNORED);
(*g_functionTable.pfnTouch) (pentTouched, pentOther);
@ -1013,7 +1016,7 @@ int Spawn (edict_t *ent)
{
REMOVE_ENTITY (ent);
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META_VALUE (MRES_SUPERCEDE, 0);
return 0;
@ -1064,7 +1067,7 @@ int Spawn (edict_t *ent)
else if (strncmp (engine.GetMapName (), "ka_", 3) == 0) // knife arena map
g_mapType |= MAP_KA;
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META_VALUE (MRES_IGNORED, 0);
int result = (*g_functionTable.pfnSpawn) (ent); // get result
@ -1082,7 +1085,7 @@ void UpdateClientData (const struct edict_s *ent, int sendweapons, struct client
if (!(g_gameFlags & GAME_LEGACY) && yb_latency_display.GetInt () == 2)
bots.SendPingDataOffsets (const_cast <edict_t *> (ent));
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META (MRES_IGNORED);
(*g_functionTable.pfnUpdateClientData) (ent, sendweapons, cd);
@ -1116,7 +1119,7 @@ int ClientConnect (edict_t *ent, const char *name, const char *addr, char reject
bots.AdjustQuota (true, ent);
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META_VALUE (MRES_IGNORED, 0);
return (*g_functionTable.pfnClientConnect) (ent, name, addr, rejectReason);
@ -1155,7 +1158,7 @@ void ClientDisconnect (edict_t *ent)
}
}
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META (MRES_IGNORED);
(*g_functionTable.pfnClientDisconnect) (ent);
@ -1184,7 +1187,7 @@ void ClientUserInfoChanged (edict_t *ent, char *infobuffer)
}
}
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META (MRES_IGNORED);
(*g_functionTable.pfnClientUserInfoChanged) (ent, infobuffer);
@ -1211,7 +1214,9 @@ void ClientCommand (edict_t *ent)
static int fillServerTeam = 5;
static bool fillCommand = false;
if (!engine.IsBotCommand () && (ent == g_hostEntity || (g_clients[engine.IndexOfEntity (ent) - 1].flags & CF_ADMIN)))
int issuerPlayerIndex = engine.IndexOfEntity (ent) - 1;
if (!engine.IsBotCommand () && (ent == g_hostEntity || (g_clients[issuerPlayerIndex].flags & CF_ADMIN)))
{
if (stricmp (command, "yapb") == 0 || stricmp (command, "yb") == 0)
{
@ -1227,14 +1232,14 @@ void ClientCommand (edict_t *ent)
engine.ClientPrintf (ent, "Command %s, can only be executed from server console.", arg1);
break;
}
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META (MRES_SUPERCEDE);
return;
}
else if (stricmp (command, "menuselect") == 0 && !IsNullString (arg1) && g_clients[engine.IndexOfEntity (ent) - 1].menu != NULL)
else if (stricmp (command, "menuselect") == 0 && !IsNullString (arg1) && g_clients[issuerPlayerIndex].menu != NULL)
{
Client *client = &g_clients[engine.IndexOfEntity (ent) - 1];
Client *client = &g_clients[issuerPlayerIndex];
int selection = atoi (arg1);
if (client->menu == &g_menus[12])
@ -1265,7 +1270,7 @@ void ClientCommand (edict_t *ent)
DisplayMenuToClient (ent, NULL);
break;
}
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META (MRES_SUPERCEDE);
return;
@ -1296,7 +1301,7 @@ void ClientCommand (edict_t *ent)
waypoints.ToggleFlags (FLAG_SNIPER);
break;
}
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META (MRES_SUPERCEDE);
return;
@ -1357,7 +1362,7 @@ void ClientCommand (edict_t *ent)
DisplayMenuToClient (ent, NULL);
break;
}
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META (MRES_SUPERCEDE);
return;
@ -1453,7 +1458,7 @@ void ClientCommand (edict_t *ent)
DisplayMenuToClient (ent, &g_menus[9]);
break;
}
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META (MRES_SUPERCEDE);
return;
@ -1469,7 +1474,7 @@ void ClientCommand (edict_t *ent)
if ((selection >= 1) && (selection <= 9))
waypoints.SetRadius (radiusValue[selection - 1]);
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META (MRES_SUPERCEDE);
return;
@ -1503,7 +1508,7 @@ void ClientCommand (edict_t *ent)
break;
}
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META (MRES_SUPERCEDE);
return;
@ -1538,7 +1543,7 @@ void ClientCommand (edict_t *ent)
DisplayMenuToClient (ent, NULL);
break;
}
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META (MRES_SUPERCEDE);
return;
@ -1581,7 +1586,7 @@ void ClientCommand (edict_t *ent)
DisplayMenuToClient (ent, NULL);
break;
}
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META (MRES_SUPERCEDE);
return;
@ -1627,7 +1632,7 @@ void ClientCommand (edict_t *ent)
break;
}
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META (MRES_SUPERCEDE);
return;
@ -1646,7 +1651,7 @@ void ClientCommand (edict_t *ent)
else
engine.CenterPrintf ("AutoPath maximum distance set to %f", g_autoPathDistance);
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META (MRES_SUPERCEDE);
return;
@ -1674,7 +1679,7 @@ void ClientCommand (edict_t *ent)
break;
}
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META (MRES_SUPERCEDE);
return;
@ -1715,7 +1720,7 @@ void ClientCommand (edict_t *ent)
if (client->menu == &g_menus[4])
DisplayMenuToClient (ent, &g_menus[4]);
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META (MRES_SUPERCEDE);
return;
@ -1741,7 +1746,7 @@ void ClientCommand (edict_t *ent)
DisplayMenuToClient (ent, NULL);
break;
}
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META (MRES_SUPERCEDE);
return;
@ -1762,7 +1767,7 @@ void ClientCommand (edict_t *ent)
DisplayMenuToClient (ent, NULL);
break;
}
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META (MRES_SUPERCEDE);
return;
@ -1795,7 +1800,7 @@ void ClientCommand (edict_t *ent)
DisplayMenuToClient (ent, NULL);
break;
}
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META (MRES_SUPERCEDE);
return;
@ -1818,7 +1823,7 @@ void ClientCommand (edict_t *ent)
DisplayMenuToClient (ent, NULL);
break;
}
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META (MRES_SUPERCEDE);
return;
@ -1842,7 +1847,7 @@ void ClientCommand (edict_t *ent)
DisplayMenuToClient (ent, NULL);
break;
}
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META (MRES_SUPERCEDE);
return;
@ -1867,7 +1872,7 @@ void ClientCommand (edict_t *ent)
DisplayMenuToClient (ent, NULL);
break;
}
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META (MRES_SUPERCEDE);
return;
@ -1897,7 +1902,7 @@ void ClientCommand (edict_t *ent)
DisplayMenuToClient (ent, &g_menus[2]);
break;
}
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META (MRES_SUPERCEDE);
return;
@ -1927,7 +1932,7 @@ void ClientCommand (edict_t *ent)
bots.RemoveMenu (ent, 1);
break;
}
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META (MRES_SUPERCEDE);
return;
@ -1957,7 +1962,7 @@ void ClientCommand (edict_t *ent)
bots.RemoveMenu (ent, 2);
break;
}
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META (MRES_SUPERCEDE);
return;
@ -1983,7 +1988,7 @@ void ClientCommand (edict_t *ent)
bots.RemoveMenu (ent, 3);
break;
}
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META (MRES_SUPERCEDE);
return;
@ -2011,7 +2016,9 @@ void ClientCommand (edict_t *ent)
for (int i = 0; i < engine.MaxClients (); i++)
{
if (!(g_clients[i].flags & CF_USED) || (team != -1 && team != g_clients[i].team) || isAlive != IsAlive (g_clients[i].ent))
const Client &client = g_clients[i];
if (!(client.flags & CF_USED) || (team != -1 && team != client.team) || isAlive != IsAlive (client.ent))
continue;
Bot *target = bots.GetBot (i);
@ -2028,10 +2035,13 @@ void ClientCommand (edict_t *ent)
}
}
}
int clientIndex = engine.IndexOfEntity (ent) - 1;
const Client &radioTarget = g_clients[clientIndex];
// check if this player alive, and issue something
if ((g_clients[clientIndex].flags & CF_ALIVE) && g_radioSelect[clientIndex] != 0 && strncmp (command, "menuselect", 10) == 0)
if ((radioTarget.flags & CF_ALIVE) && g_radioSelect[clientIndex] != 0 && strncmp (command, "menuselect", 10) == 0)
{
int radioCommand = atoi (arg1);
@ -2046,21 +2056,21 @@ void ClientCommand (edict_t *ent)
Bot *bot = bots.GetBot (i);
// validate bot
if (bot != NULL && bot->m_team == g_clients[clientIndex].team && ent != bot->GetEntity () && bot->m_radioOrder == 0)
if (bot != NULL && bot->m_team == radioTarget.team && ent != bot->GetEntity () && bot->m_radioOrder == 0)
{
bot->m_radioOrder = radioCommand;
bot->m_radioEntity = ent;
}
}
}
g_lastRadioTime[g_clients[clientIndex].team] = engine.Time ();
g_lastRadioTime[radioTarget.team] = engine.Time ();
}
g_radioSelect[clientIndex] = 0;
}
else if (strncmp (command, "radio", 5) == 0)
g_radioSelect[clientIndex] = atoi (&command[5]);
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META (MRES_IGNORED);
(*g_functionTable.pfnClientCommand) (ent);
@ -2095,7 +2105,7 @@ void ServerActivate (edict_t *pentEdictList, int edictCount, int clientMax)
}
bots.InitQuota ();
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META (MRES_IGNORED);
(*g_functionTable.pfnServerActivate) (pentEdictList, edictCount, clientMax);
@ -2124,7 +2134,7 @@ void ServerDeactivate (void)
FreeLibraryMemory ();
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META (MRES_IGNORED);
(*g_functionTable.pfnServerDeactivate) ();
@ -2147,31 +2157,32 @@ void StartFrame (void)
for (int i = 0; i < engine.MaxClients (); i++)
{
edict_t *player = engine.EntityOfIndex (i + 1);
Client &storeClient = g_clients[i];
if (!engine.IsNullEntity (player) && (player->v.flags & FL_CLIENT))
{
g_clients[i].ent = player;
g_clients[i].flags |= CF_USED;
storeClient.ent = player;
storeClient.flags |= CF_USED;
if (IsAlive (player))
g_clients[i].flags |= CF_ALIVE;
storeClient.flags |= CF_ALIVE;
else
g_clients[i].flags &= ~CF_ALIVE;
storeClient.flags &= ~CF_ALIVE;
if (g_clients[i].flags & CF_ALIVE)
if (storeClient.flags & CF_ALIVE)
{
// keep the clipping mode enabled, or it can be turned off after new round has started
if (g_hostEntity == player && g_editNoclip)
g_hostEntity->v.movetype = MOVETYPE_NOCLIP;
g_clients[i].origin = player->v.origin;
storeClient.origin = player->v.origin;
SoundSimulateUpdate (i);
}
}
else
{
g_clients[i].flags &= ~(CF_USED | CF_ALIVE);
g_clients[i].ent = NULL;
storeClient.flags &= ~(CF_USED | CF_ALIVE);
storeClient.ent = NULL;
}
}
@ -2217,7 +2228,11 @@ void StartFrame (void)
}
bots.CalculatePingOffsets ();
if (g_isMetamod)
// select the leader each team
for (int team = TERRORIST; team < SPECTATOR; team++)
bots.SelectLeaderEachTeam (team, false);
if (g_gameFlags & GAME_METAMOD)
{
static cvar_t *csdm_active;
static cvar_t *mp_freeforall;
@ -2240,7 +2255,7 @@ void StartFrame (void)
// keep bot number up to date
bots.MaintainBotQuota ();
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META (MRES_IGNORED);
(*g_functionTable.pfnStartFrame) ();
@ -2310,7 +2325,7 @@ void pfnChangeLevel (char *s1, char *s2)
waypoints.SaveExperienceTab ();
waypoints.SaveVisibilityTab ();
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META (MRES_IGNORED);
CHANGE_LEVEL (s1, s2);
@ -2322,7 +2337,7 @@ edict_t *pfnFindEntityByString (edict_t *edictStartSearchAfter, const char *fiel
if (strcmp (value, "info_map_parameters") == 0)
RoundInit ();
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META_VALUE (MRES_IGNORED, 0);
return FIND_ENTITY_BY_STRING (edictStartSearchAfter, field, value);
@ -2342,7 +2357,7 @@ void pfnEmitSound (edict_t *entity, int channel, const char *sample, float volum
SoundAttachToClients (entity, sample, volume);
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META (MRES_IGNORED);
(*g_engfuncs.pfnEmitSound) (entity, channel, sample, volume, attenuation, flags, pitch);
@ -2374,13 +2389,13 @@ void pfnClientCommand (edict_t *ent, char const *format, ...)
// is the target entity an official bot, or a third party bot ?
if (ent->v.flags & FL_FAKECLIENT)
{
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META (MRES_SUPERCEDE); // prevent bots to be forced to issue client commands
return;
}
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META (MRES_IGNORED);
CLIENT_COMMAND (ent, buffer);
@ -2391,7 +2406,7 @@ void pfnMessageBegin (int msgDest, int msgType, const float *origin, edict_t *ed
// this function called each time a message is about to sent.
// store the message type in our own variables, since the GET_USER_MSG_ID () will just do a lot of strcmp()'s...
if (g_isMetamod && engine.FindMessageId (NETMSG_MONEY) == -1)
if ((g_gameFlags & GAME_METAMOD) && engine.FindMessageId (NETMSG_MONEY) == -1)
{
engine.AssignMessageId (NETMSG_VGUI, GET_USER_MSG_ID (PLID, "VGUIMenu", NULL));
engine.AssignMessageId (NETMSG_SHOWMENU, GET_USER_MSG_ID (PLID, "ShowMenu", NULL));
@ -2462,7 +2477,7 @@ void pfnMessageBegin (int msgDest, int msgType, const float *origin, edict_t *ed
}
}
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META (MRES_IGNORED);
MESSAGE_BEGIN (msgDest, msgType, origin, ed);
@ -2472,7 +2487,7 @@ void pfnMessageEnd (void)
{
engine.ResetMessageCapture ();
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META (MRES_IGNORED);
MESSAGE_END ();
@ -2494,7 +2509,7 @@ void pfnWriteByte (int value)
// if this message is for a bot, call the client message function...
engine.ProcessMessageCapture ((void *) &value);
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META (MRES_IGNORED);
WRITE_BYTE (value);
@ -2505,7 +2520,7 @@ void pfnWriteChar (int value)
// if this message is for a bot, call the client message function...
engine.ProcessMessageCapture ((void *) &value);
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META (MRES_IGNORED);
WRITE_CHAR (value);
@ -2516,7 +2531,7 @@ void pfnWriteShort (int value)
// if this message is for a bot, call the client message function...
engine.ProcessMessageCapture ((void *) &value);
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META (MRES_IGNORED);
WRITE_SHORT (value);
@ -2527,7 +2542,7 @@ void pfnWriteLong (int value)
// if this message is for a bot, call the client message function...
engine.ProcessMessageCapture ((void *) &value);
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META (MRES_IGNORED);
WRITE_LONG (value);
@ -2538,7 +2553,7 @@ void pfnWriteAngle (float value)
// if this message is for a bot, call the client message function...
engine.ProcessMessageCapture ((void *) &value);
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META (MRES_IGNORED);
WRITE_ANGLE (value);
@ -2549,7 +2564,7 @@ void pfnWriteCoord (float value)
// if this message is for a bot, call the client message function...
engine.ProcessMessageCapture ((void *) &value);
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META (MRES_IGNORED);
WRITE_COORD (value);
@ -2560,7 +2575,7 @@ void pfnWriteString (const char *sz)
// if this message is for a bot, call the client message function...
engine.ProcessMessageCapture ((void *) sz);
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META (MRES_IGNORED);
WRITE_STRING (sz);
@ -2571,7 +2586,7 @@ void pfnWriteEntity (int value)
// if this message is for a bot, call the client message function...
engine.ProcessMessageCapture ((void *) &value);
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META (MRES_IGNORED);
WRITE_ENTITY (value);
@ -2589,13 +2604,13 @@ int pfnCmd_Argc (void)
// is this a bot issuing that client command?
if (engine.IsBotCommand ())
{
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META_VALUE (MRES_SUPERCEDE, engine.GetOverrideArgc ());
return engine.GetOverrideArgc (); // if so, then return the argument count we know
}
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META_VALUE (MRES_IGNORED, 0);
return CMD_ARGC (); // ask the engine how many arguments there are
@ -2613,13 +2628,13 @@ const char *pfnCmd_Args (void)
// is this a bot issuing that client command?
if (engine.IsBotCommand ())
{
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META_VALUE (MRES_SUPERCEDE, engine.GetOverrideArgs ());
return engine.GetOverrideArgs (); // else return the whole bot client command string we know
}
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META_VALUE (MRES_IGNORED, NULL);
return CMD_ARGS (); // ask the client command string to the engine
@ -2637,12 +2652,12 @@ const char *pfnCmd_Argv (int argc)
// is this a bot issuing that client command?
if (engine.IsBotCommand ())
{
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META_VALUE (MRES_SUPERCEDE, engine.GetOverrideArgv (argc));
return engine.GetOverrideArgv (argc); // if so, then return the wanted argument we know
}
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META_VALUE (MRES_IGNORED, NULL);
return CMD_ARGV (argc); // ask the argument number "argc" to the engine
@ -2658,13 +2673,13 @@ void pfnClientPrintf (edict_t *ent, PRINT_TYPE printType, const char *message)
if (IsValidBot (ent))
{
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META (MRES_SUPERCEDE);
return;
}
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META (MRES_IGNORED);
CLIENT_PRINTF (ent, printType, message);
@ -2678,7 +2693,7 @@ void pfnSetClientMaxspeed (const edict_t *ent, float newMaxspeed)
if (bot != NULL)
bot->pev->maxspeed = newMaxspeed;
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META (MRES_IGNORED);
(*g_engfuncs.pfnSetClientMaxspeed) (ent, newMaxspeed);
@ -2696,7 +2711,7 @@ int pfnRegUserMsg (const char *name, int size)
// using pfnMessageBegin (), it will know what message ID number to send, and the engine will
// know what to do, only for non-metamod version
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META_VALUE (MRES_IGNORED, 0);
int message = REG_USER_MSG (name, size);
@ -2767,7 +2782,7 @@ void pfnAlertMessage (ALERT_TYPE alertType, char *format, ...)
}
}
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
RETURN_META (MRES_IGNORED);
(*g_engfuncs.pfnAlertMessage) (alertType, buffer);
@ -2789,14 +2804,16 @@ SHARED_LIBRARAY_EXPORT int GetEntityAPI2 (gamefuncs_t *functionTable, int *)
memset (functionTable, 0, sizeof (gamefuncs_t));
if (!g_isMetamod)
if (!(g_gameFlags & GAME_METAMOD))
{
auto api_GetEntityAPI = g_gameLib->GetFuncAddr <EntityAPI_t> ("GetEntityAPI");
// pass other DLLs engine callbacks to function table...
if ((*g_entityAPI) (&g_functionTable, INTERFACE_VERSION) == 0)
{
AddLogEntry (true, LL_FATAL, "GetEntityAPI2: ERROR - Not Initialized.");
return FALSE; // error initializing function table!!!
}
if (api_GetEntityAPI (&g_functionTable, INTERFACE_VERSION) == 0)
{
AddLogEntry (true, LL_FATAL, "GetEntityAPI2: ERROR - Not Initialized.");
return FALSE; // error initializing function table!!!
}
gameDLLFunc.dllapi_table = &g_functionTable;
gpGamedllFuncs = &gameDLLFunc;
@ -2848,10 +2865,12 @@ SHARED_LIBRARAY_EXPORT int GetNewDLLFunctions (newgamefuncs_t *functionTable, in
// pass them too, else the DLL interfacing wouldn't be complete and the game possibly wouldn't
// run properly.
if (g_getNewEntityAPI == NULL)
auto api_GetNewDLLFunctions = g_gameLib->GetFuncAddr <NewEntityAPI_t> ("GetNewDLLFunctions");
if (api_GetNewDLLFunctions == NULL)
return FALSE;
if (!(*g_getNewEntityAPI) (functionTable, interfaceVersion))
if (!api_GetNewDLLFunctions (functionTable, interfaceVersion))
{
AddLogEntry (true, LL_FATAL, "GetNewDLLFunctions: ERROR - Not Initialized.");
return FALSE;
@ -2863,7 +2882,7 @@ SHARED_LIBRARAY_EXPORT int GetNewDLLFunctions (newgamefuncs_t *functionTable, in
SHARED_LIBRARAY_EXPORT int GetEngineFunctions (enginefuncs_t *functionTable, int *)
{
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
memset (functionTable, 0, sizeof (enginefuncs_t));
functionTable->pfnChangeLevel = pfnChangeLevel;
@ -2906,10 +2925,12 @@ SHARED_LIBRARAY_EXPORT int Server_GetBlendingInterface (int version, void **ppin
// of the body move, which bones, which hitboxes and how) between the server and the game DLL.
// some MODs can be using a different hitbox scheme than the standard one.
if (g_serverBlendingAPI == NULL)
auto api_GetBlendingInterface = g_gameLib->GetFuncAddr <BlendAPI_t> ("Server_GetBlendingInterface");
if (api_GetBlendingInterface == NULL)
return FALSE;
return (*g_serverBlendingAPI) (version, ppinterface, pstudio, rotationmatrix, bonetransform);
return api_GetBlendingInterface (version, ppinterface, pstudio, rotationmatrix, bonetransform);
}
SHARED_LIBRARAY_EXPORT int Meta_Query (char *, plugin_info_t **pPlugInfo, mutil_funcs_t *pMetaUtilFuncs)
@ -2954,7 +2975,7 @@ SHARED_LIBRARAY_EXPORT void Meta_Init (void)
// this function is called by metamod, before any other interface functions. Purpose of this
// function to give plugin a chance to determine is plugin running under metamod or not.
g_isMetamod = true;
g_gameFlags |= GAME_METAMOD;
}
Library *LoadCSBinary (void)
@ -2987,7 +3008,7 @@ Library *LoadCSBinary (void)
{
g_gameFlags |= GAME_CZERO;
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
return NULL;
return new Library (path);
@ -3008,7 +3029,7 @@ Library *LoadCSBinary (void)
{
g_gameFlags |= (GAME_LEGACY | GAME_XASH);
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
{
delete game;
return NULL;
@ -3024,7 +3045,7 @@ Library *LoadCSBinary (void)
else
g_gameFlags |= GAME_LEGACY;
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
{
delete game;
return NULL;
@ -3067,7 +3088,7 @@ DLL_GIVEFNPTRSTODLL GiveFnptrsToDll (enginefuncs_t *functionTable, globalvars_t
#ifdef PLATFORM_ANDROID
g_gameFlags |= (GAME_LEGACY | GAME_XASH | GAME_MOBILITY);
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
return; // we should stop the attempt for loading the real gamedll, since metamod handle this for us
#ifdef LOAD_HARDFP
@ -3086,7 +3107,7 @@ DLL_GIVEFNPTRSTODLL GiveFnptrsToDll (enginefuncs_t *functionTable, globalvars_t
#else
g_gameLib = LoadCSBinary ();
{
if (g_gameLib == NULL && !g_isMetamod)
if (g_gameLib == NULL && !(g_gameFlags & GAME_METAMOD))
{
AddLogEntry (true, LL_FATAL | LL_IGNORE, "Mod that you has started, not supported by this bot (gamedir: %s)", engine.GetModName ());
return;
@ -3115,23 +3136,20 @@ DLL_GIVEFNPTRSTODLL GiveFnptrsToDll (enginefuncs_t *functionTable, globalvars_t
}
engine.Printf ("YaPB Bot has detect game version as Counter-Strike: %s", gameVersionStr.GetBuffer ());
if (g_isMetamod)
if (g_gameFlags & GAME_METAMOD)
return;
}
#endif
g_funcPointers = g_gameLib->GetFuncAddr <FuncPointers_t> ("GiveFnptrsToDll");
g_entityAPI = g_gameLib->GetFuncAddr <EntityAPI_t> ("GetEntityAPI");
g_getNewEntityAPI = g_gameLib->GetFuncAddr <NewEntityAPI_t> ("GetNewDLLFunctions");
g_serverBlendingAPI = g_gameLib->GetFuncAddr <BlendAPI_t> ("Server_GetBlendingInterface");
auto api_GiveFnptrsToDll = g_gameLib->GetFuncAddr <FuncPointers_t> ("GiveFnptrsToDll");
if (!g_funcPointers || !g_entityAPI)
if (!api_GiveFnptrsToDll)
TerminateOnMalloc ();
GetEngineFunctions (functionTable, NULL);
// give the engine functions to the other DLL...
(*g_funcPointers) (functionTable, pGlobals);
api_GiveFnptrsToDll (functionTable, pGlobals);
}
DLL_ENTRYPOINT