const char *GetModName (void) { static char modName[256]; GET_GAME_DIR (modName); // ask the engine for the MOD directory path int length = strlen (modName); // get the length of the returned string // format the returned string to get the last directory name int stop = length - 1; while ((modName[stop] == '\\' || modName[stop] == '/') && stop > 0) stop--; // shift back any trailing separator int start = stop; while (modName[start] != '\\' && modName[start] != '/' && start > 0) start--; // shift back to the start of the last subdirectory name if (modName[start] == '\\' || modName[start] == '/') start++; // if we reached a separator, step over it // now copy the formatted string back onto itself character per character for (length = start; length <= stop; length++) modName[length - start] = modName[length]; modName[length - start] = 0; // terminate the string return &modName[0]; }
void UTIL_BuildFileName(char *filename, char *arg1, char *arg2) { GET_GAME_DIR(filename); strcat(filename, "/"); if ((arg1) && (*arg1) && (arg2) && (*arg2)) { strcat(filename, arg1); strcat(filename, "/"); strcat(filename, arg2); } else if ((arg1) && (*arg1)) { strcat(filename, arg1); } }
void ErrorMessage ( const char *message ) { char path[MAX_PATH]; GET_GAME_DIR(path); strcat(path, "/ss_errlog.txt"); FILE* pf = fopen(path, "a"); if (pf) { fprintf(pf, "ERROR: %s\n", message); fclose(pf); } ++errors; }
void PrintSequence ( const char *begin, const char *end ) { char path[MAX_PATH]; GET_GAME_DIR(path); strcat(path, "/ss_errlog.txt"); FILE* pf = fopen(path, "a"); if (pf) { fputc('\"', pf); for (char *c = (char*)begin; c < end; fputc(*(c++), pf)); fprintf(pf, "\"\n"); fclose(pf); } }
extern "C" void GiveFnptrsToDll( enginefuncs_t* pengfuncsFromEngine, globalvars_t *pGlobals ) #endif { // get the engine functions from the engine... memcpy( &g_engfuncs, pengfuncsFromEngine, sizeof(enginefuncs_t) ); // get the globals from the engine gpGlobals = pGlobals; // get the directory name of the currently running game or mod // this now returns just the mod directory's name: http://metamod.org/engine_notes.html#GetGameDir char szGameDir[256]; char *szLibraryPath = ""; GET_GAME_DIR(szGameDir); if( !strcmpi( szGameDir, "valve" ) ) { mod_id = VALVE_DLL; #ifndef __linux__ szLibraryPath = "valve/dlls/hl.dll"; #else szLibraryPath = "valve/dlls/hl.so"; #endif if( !g_bIsMMPlugin ) { #ifndef __linux__ h_Library = LoadLibrary( szLibraryPath ); #else h_Library = dlopen( szLibraryPath, RTLD_NOW ); #endif } } else if( !strcmpi( szGameDir, "bshift" ) ) { mod_id = BSHIFT_DLL; #ifndef __linux__ szLibraryPath = "bshift/dlls/hl.dll"; #else szLibraryPath = "bshift/dlls/bshift.so"; #endif if( !g_bIsMMPlugin ) { #ifndef __linux__ h_Library = LoadLibrary( szLibraryPath ); #else h_Library = dlopen( szLibraryPath, RTLD_NOW ); #endif } } else if( !strcmpi( szGameDir, "gearbox" ) ) { mod_id = GEARBOX_DLL; #ifndef __linux__ szLibraryPath = "gearbox/dlls/opfor.dll"; #else szLibraryPath = "gearbox/dlls/opfor.so"; #endif if( !g_bIsMMPlugin ) { #ifndef __linux__ h_Library = LoadLibrary( szLibraryPath ); #else h_Library = dlopen( szLibraryPath, RTLD_NOW ); #endif } } else if( !strcmpi( szGameDir, "decay" ) ) { mod_id = DECAY_DLL; #ifndef __linux__ szLibraryPath = "decay/dlls/decay.dll"; #else szLibraryPath = "decay/dlls/decay_i386.so"; #endif if( !g_bIsMMPlugin ) { #ifndef __linux__ h_Library = LoadLibrary( szLibraryPath ); #else h_Library = dlopen( szLibraryPath, RTLD_NOW ); #endif } } else if( !strcmpi( szGameDir, "cstrike" ) ) { mod_id = CSTRIKE_DLL; #ifndef __linux__ szLibraryPath = "cstrike/dlls/mp.dll"; #else szLibraryPath = "cstrike/dlls/cs.so"; #endif if( !g_bIsMMPlugin ) { #ifndef __linux__ h_Library = LoadLibrary( szLibraryPath ); #else h_Library = dlopen( szLibraryPath, RTLD_NOW ); #endif } } else if( !strcmpi( szGameDir, "czero" ) ) { mod_id = CZERO_DLL; #ifndef __linux__ szLibraryPath = "czero/dlls/mp.dll"; #else szLibraryPath = "czero/dlls/cs.so"; #endif if( !g_bIsMMPlugin ) { #ifndef __linux__ h_Library = LoadLibrary( szLibraryPath ); #else h_Library = dlopen( szLibraryPath, RTLD_NOW ); #endif } } else if( !strcmpi( szGameDir, "czeror" ) ) { mod_id = CZEROR_DLL; #ifndef __linux__ szLibraryPath = "czeror/dlls/cz.dll"; #else szLibraryPath = "czeror/dlls/cz.so"; #endif if( !g_bIsMMPlugin ) { #ifndef __linux__ h_Library = LoadLibrary( szLibraryPath ); #else h_Library = dlopen( szLibraryPath, RTLD_NOW ); #endif } } else if( !strcmpi( szGameDir, "dod" ) ) { mod_id = DOD_DLL; #ifndef __linux__ szLibraryPath = "dod/dlls/dod.dll"; #else szLibraryPath = "dod/dlls/dod.so"; #endif if( !g_bIsMMPlugin ) { #ifndef __linux__ h_Library = LoadLibrary( szLibraryPath ); #else h_Library = dlopen( szLibraryPath, RTLD_NOW ); #endif } } else if( !strcmpi( szGameDir, "tfc" ) ) { mod_id = TFC_DLL; #ifndef __linux__ szLibraryPath = "tfc/dlls/tfc.dll"; #else szLibraryPath = "tfc/dlls/tfc.so"; #endif if( !g_bIsMMPlugin ) { #ifndef __linux__ h_Library = LoadLibrary( szLibraryPath ); #else h_Library = dlopen( szLibraryPath, RTLD_NOW ); #endif } } else if( !strcmpi( szGameDir, "rewolf" ) ) { mod_id = REWOLF_DLL; #ifndef __linux__ szLibraryPath = "rewolf/dlls/gunman.dll"; #else szLibraryPath = nullptr; #endif if( !g_bIsMMPlugin ) { #ifndef __linux__ h_Library = LoadLibrary( szLibraryPath ); #else h_Library = nullptr; #endif } } else if( !strcmpi( szGameDir, "hunger" ) ) { mod_id = HUNGER_DLL; #ifndef __linux__ szLibraryPath = "hunger/dlls/einar.dll"; #else szLibraryPath = nullptr; #endif if( !g_bIsMMPlugin ) { #ifndef __linux__ h_Library = LoadLibrary( szLibraryPath ); #else h_Library = nullptr; #endif } } else if( !strcmpi( szGameDir , "ns") ) { mod_id = NS_DLL; #ifndef __linux__ szLibraryPath = "ns/dlls/ns.dll"; #else szLibraryPath = "ns/dlls/ns_i386.so"; #endif if( !g_bIsMMPlugin ) { #ifndef __linux__ h_Library = LoadLibrary( szLibraryPath ); #else h_Library = dlopen( szLibraryPath, RTLD_NOW ); #endif } } else if( strcmpi( szGameDir, "ship" ) ) { mod_id = SHIP_DLL; #ifndef __linux__ szLibraryPath = "ship/dlls/ship.dll"; #else szLibraryPath = "ship/dlls/ship_i386.so"; #endif if( !g_bIsMMPlugin ) { #ifndef __linux__ h_Library = LoadLibrary( szLibraryPath ); #else h_Library = dlopen( szLibraryPath, RTLD_NOW ); #endif } } strncpy( g_szLibraryPath, szLibraryPath, strlen( szLibraryPath ) ); if( !g_bIsMMPlugin && h_Library == nullptr ) { ALERT( at_error, "Library not found or not supported!\n" ); } extern bot_player_t g_valveBots[]; extern bot_player_t g_gearboxBots[]; extern bot_player_t g_dodBots[]; extern bot_player_t g_gunmanBots[]; extern bot_player_t g_nsBots[]; extern bot_player_t g_hungerBots[]; extern bot_player_t g_shipBots[]; if( mod_id == VALVE_DLL || mod_id == TFC_DLL ) { pBotData = g_valveBots; } else if( mod_id == GEARBOX_DLL ) { pBotData = g_gearboxBots; } else if( mod_id == DOD_DLL ) { pBotData = g_dodBots; } else if( mod_id == REWOLF_DLL ) { pBotData = g_gunmanBots; } else if( mod_id == NS_DLL ) { pBotData = g_nsBots; } else if( mod_id == HUNGER_DLL ) { pBotData = g_hungerBots; } else if( mod_id == SHIP_DLL ) { pBotData = g_shipBots; } LoadExtraExports(); if( g_bIsMMPlugin ) { return; } GetEngineFunctions( pengfuncsFromEngine, nullptr ); // give the engine functions to the other DLL... (*(GIVEFNPTRSTODLL)GetProcAddress( h_Library, "GiveFnptrsToDll" ))(pengfuncsFromEngine, pGlobals); // finished, interfacing from gamedll to engine complete return; }
/* <36ace2> ../cstrike/dlls/bot/cs_bot_manager.cpp:484 */ void CCSBotManager::__MAKE_VHOOK(ServerCommand)(const char *pcmd) { if (!m_bServerActive || !UTIL_IsGame("czero")) return; char buffer[400]; const char *msg = CMD_ARGV(1); if (FStrEq(pcmd, "bot_about")) { Q_sprintf(buffer, "\n--------------------------------------------------------------------------\nThe Official Counter-Strike Bot V%d.%02d\nCreated by Michael S. Booth\nWeb: www.turtlerockstudios.com\\csbot\nE-mail: [email protected]\n--------------------------------------------------------------------------\n\n", CSBOT_VERSION_MAJOR, CSBOT_VERSION_MINOR); CONSOLE_ECHO(buffer); HintMessageToAllPlayers(buffer); } else if (FStrEq(pcmd, "bot_add")) { BotAddCommand(BOT_TEAM_ANY); } else if (FStrEq(pcmd, "bot_add_t")) { BotAddCommand(BOT_TEAM_T); } else if (FStrEq(pcmd, "bot_add_ct")) { BotAddCommand(BOT_TEAM_CT); } else if (FStrEq(pcmd, "bot_kill")) { bool killThemAll; if (CMD_ARGC() == 1 || FStrEq(msg, "all")) killThemAll = true; else killThemAll = false; for (int iIndex = 1; iIndex <= gpGlobals->maxClients; iIndex++) { CBasePlayer *pPlayer = (CBasePlayer *)UTIL_PlayerByIndex(iIndex); if (pPlayer == NULL) continue; if (FNullEnt(pPlayer->pev)) continue; const char *name = STRING(pPlayer->pev->netname); if (FStrEq(name, "")) continue; if (pPlayer->IsBot()) { if (killThemAll || FStrEq(name, msg)) { pPlayer->TakeDamage(pPlayer->pev, pPlayer->pev, 9999.9f, DMG_CRUSH); } } } } else if (FStrEq(pcmd, "bot_kick")) { bool kickThemAll; if (CMD_ARGC() == 1 || FStrEq(msg, "all")) kickThemAll = true; else kickThemAll = false; for (int iIndex = 1; iIndex <= gpGlobals->maxClients; iIndex++) { CBasePlayer *pPlayer = (CBasePlayer *)UTIL_PlayerByIndex(iIndex); if (pPlayer == NULL) continue; if (FNullEnt(pPlayer->pev)) continue; const char *name = STRING(pPlayer->pev->netname); if (FStrEq(name, "")) continue; if (pPlayer->IsBot()) { if (kickThemAll || FStrEq(name, msg)) { SERVER_COMMAND(UTIL_VarArgs("kick \"%s\"\n", name)); CVAR_SET_FLOAT("bot_quota", cv_bot_quota.value - 1); } } } if (kickThemAll || cv_bot_quota.value < 0.0f) { CVAR_SET_FLOAT("bot_quota", 0); } } else if (FStrEq(pcmd, "bot_knives_only")) { CVAR_SET_FLOAT("bot_allow_pistols", 0); CVAR_SET_FLOAT("bot_allow_shotguns", 0); CVAR_SET_FLOAT("bot_allow_sub_machine_guns", 0); CVAR_SET_FLOAT("bot_allow_rifles", 0); CVAR_SET_FLOAT("bot_allow_machine_guns", 0); CVAR_SET_FLOAT("bot_allow_grenades", 0); CVAR_SET_FLOAT("bot_allow_snipers", 0); CVAR_SET_FLOAT("bot_allow_shield", 0); } else if (FStrEq(pcmd, "bot_pistols_only")) { CVAR_SET_FLOAT("bot_allow_pistols", 1); CVAR_SET_FLOAT("bot_allow_shotguns", 0); CVAR_SET_FLOAT("bot_allow_sub_machine_guns", 0); CVAR_SET_FLOAT("bot_allow_rifles", 0); CVAR_SET_FLOAT("bot_allow_machine_guns", 0); CVAR_SET_FLOAT("bot_allow_grenades", 0); CVAR_SET_FLOAT("bot_allow_snipers", 0); CVAR_SET_FLOAT("bot_allow_shield", 0); } else if (FStrEq(pcmd, "bot_snipers_only")) { CVAR_SET_FLOAT("bot_allow_pistols", 1); CVAR_SET_FLOAT("bot_allow_shotguns", 0); CVAR_SET_FLOAT("bot_allow_sub_machine_guns", 0); CVAR_SET_FLOAT("bot_allow_rifles", 0); CVAR_SET_FLOAT("bot_allow_machine_guns", 0); CVAR_SET_FLOAT("bot_allow_grenades", 0); CVAR_SET_FLOAT("bot_allow_snipers", 1); CVAR_SET_FLOAT("bot_allow_shield", 0); } else if (FStrEq(pcmd, "bot_all_weapons")) { CVAR_SET_FLOAT("bot_allow_pistols", 1); CVAR_SET_FLOAT("bot_allow_shotguns", 1); CVAR_SET_FLOAT("bot_allow_sub_machine_guns", 1); CVAR_SET_FLOAT("bot_allow_rifles", 1); CVAR_SET_FLOAT("bot_allow_machine_guns", 1); CVAR_SET_FLOAT("bot_allow_grenades", 1); CVAR_SET_FLOAT("bot_allow_snipers", 1); CVAR_SET_FLOAT("bot_allow_shield", 1); } else if (FStrEq(pcmd, "entity_dump")) { PrintAllEntities(); } else if (FStrEq(pcmd, "bot_nav_delete")) { IMPLEMENT_ARRAY_CLASS(CCSBotManager, m_editCmd) = EDIT_DELETE; } else if (FStrEq(pcmd, "bot_nav_split")) { IMPLEMENT_ARRAY_CLASS(CCSBotManager, m_editCmd) = EDIT_SPLIT; } else if (FStrEq(pcmd, "bot_nav_merge")) { IMPLEMENT_ARRAY_CLASS(CCSBotManager, m_editCmd) = EDIT_MERGE; } else if (FStrEq(pcmd, "bot_nav_mark")) { IMPLEMENT_ARRAY_CLASS(CCSBotManager, m_editCmd) = EDIT_MARK; } else if (FStrEq(pcmd, "bot_nav_begin_area")) { IMPLEMENT_ARRAY_CLASS(CCSBotManager, m_editCmd) = EDIT_BEGIN_AREA; } else if (FStrEq(pcmd, "bot_nav_end_area")) { IMPLEMENT_ARRAY_CLASS(CCSBotManager, m_editCmd) = EDIT_END_AREA; } else if (FStrEq(pcmd, "bot_nav_connect")) { IMPLEMENT_ARRAY_CLASS(CCSBotManager, m_editCmd) = EDIT_CONNECT; } else if (FStrEq(pcmd, "bot_nav_disconnect")) { IMPLEMENT_ARRAY_CLASS(CCSBotManager, m_editCmd) = EDIT_DISCONNECT; } else if (FStrEq(pcmd, "bot_nav_splice")) { IMPLEMENT_ARRAY_CLASS(CCSBotManager, m_editCmd) = EDIT_SPLICE; } else if (FStrEq(pcmd, "bot_nav_crouch")) { IMPLEMENT_ARRAY_CLASS(CCSBotManager, m_editCmd) = EDIT_ATTRIB_CROUCH; } else if (FStrEq(pcmd, "bot_nav_jump")) { IMPLEMENT_ARRAY_CLASS(CCSBotManager, m_editCmd) = EDIT_ATTRIB_JUMP; } else if (FStrEq(pcmd, "bot_nav_precise")) { IMPLEMENT_ARRAY_CLASS(CCSBotManager, m_editCmd) = EDIT_ATTRIB_PRECISE; } else if (FStrEq(pcmd, "bot_nav_no_jump")) { IMPLEMENT_ARRAY_CLASS(CCSBotManager, m_editCmd) = EDIT_ATTRIB_NO_JUMP; } else if (FStrEq(pcmd, "bot_nav_analyze")) { IMPLEMENT_ARRAY_CLASS(CCSBotManager, m_isAnalysisRequested) = true; } else if (FStrEq(pcmd, "bot_nav_strip")) { StripNavigationAreas();// TODO: reverse me } else if (FStrEq(pcmd, "bot_nav_save")) { GET_GAME_DIR(buffer); buffer[ Q_strlen(buffer) ] = '\\'; Q_strcat(buffer, CBotManager::GetNavMapFilename()); if (SaveNavigationMap(buffer))// TODO: reverse me CONSOLE_ECHO("Navigation map '%s' saved.\n", buffer); else CONSOLE_ECHO("ERROR: Cannot save navigation map '%s'.\n", buffer); } else if (FStrEq(pcmd, "bot_nav_load")) { ValidateMapData(); } else if (FStrEq(pcmd, "bot_nav_use_place")) { if (CMD_ARGC() == 1) { int i = 0; const BotPhraseList *placeList = TheBotPhrases->GetPlaceList(); for (BotPhraseList::const_iterator iter = placeList->begin(); iter != placeList->end(); ++iter, i++) { if ((*iter)->GetID() == GetNavPlace()) CONSOLE_ECHO("--> %-26s", (*iter)->GetName()); else CONSOLE_ECHO("%-30s", (*iter)->GetName()); if (!(i % 3)) CONSOLE_ECHO("\n"); } CONSOLE_ECHO("\n"); } else { const BotPhraseList *placeList = TheBotPhrases->GetPlaceList(); const BotPhrase *found = NULL; bool isAmbiguous = false; for (BotPhraseList::const_iterator iter = placeList->begin(); iter != placeList->end(); ++iter) { if (!Q_strnicmp((*iter)->GetName(), msg, Q_strlen(msg))) { if (!Q_strcmp((*iter)->GetName(), msg)) { found = (*iter); break; } if (found != NULL) isAmbiguous = true; else found = (*iter); } } if (isAmbiguous) { CONSOLE_ECHO("Ambiguous\n"); return; } if (found != NULL) { CONSOLE_ECHO("Current place set to '%s'\n", found->GetName()); m_navPlace = found->GetID(); } } } else if (FStrEq(pcmd, "bot_nav_toggle_place_mode")) { IMPLEMENT_ARRAY_CLASS(CCSBotManager, m_editCmd) = EDIT_TOGGLE_PLACE_MODE; } else if (FStrEq(pcmd, "bot_nav_place_floodfill")) { IMPLEMENT_ARRAY_CLASS(CCSBotManager, m_editCmd) = EDIT_PLACE_FLOODFILL; } else if (FStrEq(pcmd, "bot_nav_place_pick")) { IMPLEMENT_ARRAY_CLASS(CCSBotManager, m_editCmd) = EDIT_PLACE_PICK; } else if (FStrEq(pcmd, "bot_nav_toggle_place_painting")) { IMPLEMENT_ARRAY_CLASS(CCSBotManager, m_editCmd) = EDIT_TOGGLE_PLACE_PAINTING; } else if (FStrEq(pcmd, "bot_goto_mark")) { // tell the first bot we find to go to our marked area CNavArea *area = GetMarkedArea();// TODO: reverse me if (area != NULL) { CBaseEntity *pEntity = NULL; while ((pEntity = UTIL_FindEntityByClassname(pEntity, "player")) != NULL) { if (!pEntity->IsPlayer()) continue; if ((pEntity->pev->flags & FL_DORMANT) == FL_DORMANT) continue; CBasePlayer *playerOrBot = GetClassPtr((CBasePlayer *)pEntity->pev); if (playerOrBot->IsBot()) { CCSBot *bot = reinterpret_cast<CCSBot *>(playerOrBot); bot->MoveTo(&area->m_center, FASTEST_ROUTE);// TODO: reverse me return; } } } } else if (FStrEq(pcmd, "bot_memory_usage")) { CONSOLE_ECHO("Memory usage:\n"); CONSOLE_ECHO(" %d bytes per bot\b", sizeof(CCSBot)); CONSOLE_ECHO(" %d Navigation Areas @ %d bytes each = %d bytes\n", TheNavAreaGrid.GetNavAreaCount(), sizeof(CNavArea), TheNavAreaGrid.GetNavAreaCount() * sizeof(CNavArea)); CONSOLE_ECHO(" %d Hiding Spots @ %d bytes each = %d bytes\n", TheHidingSpotList.size(), sizeof(HidingSpot), sizeof(HidingSpot) * TheHidingSpotList.size()); unsigned int encounterMem = 0; for (NavAreaList::iterator iter = TheNavAreaList.begin(); iter != TheNavAreaList.end(); ++iter) { CNavArea *area = (*iter); for (SpotEncounterList::iterator siter = area->m_spotEncounterList.begin(); siter != area->m_spotEncounterList.end(); ++siter) { // TODO: Fix me, this is crashed in HOOK_GAMEDLL SpotEncounter se = (*siter); encounterMem += sizeof(SpotEncounter); encounterMem += sizeof(SpotOrder) * se.spotList.size(); } } CONSOLE_ECHO(" Encounter Spot data = %d bytes\n", encounterMem); } else if (FStrEq(pcmd, "bot_nav_mark_unnamed")) { IMPLEMENT_ARRAY_CLASS(CCSBotManager, m_editCmd) = EDIT_MARK_UNNAMED; } else if (FStrEq(pcmd, "bot_nav_warp")) { IMPLEMENT_ARRAY_CLASS(CCSBotManager, m_editCmd) = EDIT_WARP_TO_MARK; } else if (FStrEq(pcmd, "bot_nav_corner_select")) { IMPLEMENT_ARRAY_CLASS(CCSBotManager, m_editCmd) = EDIT_SELECT_CORNER; } else if (FStrEq(pcmd, "bot_nav_corner_raise")) { IMPLEMENT_ARRAY_CLASS(CCSBotManager, m_editCmd) = EDIT_RAISE_CORNER; } else if (FStrEq(pcmd, "bot_nav_corner_lower")) { IMPLEMENT_ARRAY_CLASS(CCSBotManager, m_editCmd) = EDIT_LOWER_CORNER; } else if (FStrEq(pcmd, "bot_nav_check_consistency")) { if (CMD_ARGC() != 2) { CONSOLE_ECHO("usage: bot_nav_check_consistency <filename>\n"); return; } SanityCheckNavigationMap(msg);// TODO: reverse me } }